boolean 은 true 또는 false 둘 중 하나를 갖는다.
(각 boolean 변수는 메모리의 1바이트를 차지한다.)
예제 코드
이 코드는 boolean 자료형을 어떻게 쓰는지 보여준다.
int LEDpin = 5; // LED on pin 5
int switchPin = 13; // momentary 스위치는 13에, 다른쪽은 ground 연결
boolean running = false;
void setup()
{
pinMode(LEDpin, OUTPUT);
pinMode(switchPin, INPUT);
digitalWrite(switchPin, HIGH); // 풀업 저항 켬
}
void loop()
{
if (digitalRead(switchPin) == LOW)
{ // 스위치 눌림 - pullup keeps pin high normally
delay(100); // 스위치 디바운스를 위해 기다림
running = !running; // 실행변수 토글
digitalWrite(LEDpin, running); // LED를 통해 가리킴
}
}
더보기
Title
Arduino Newsletter
We care about the privacy and personal data of our users.
To continue, please give us your consent:
Please confirm that you have read the privacy policy
Thank you for subscribing!
Curious to learn more?
Are you also a teacher, student, or professional that loves using Arduino in your day-to-day activities?
Then keep up-to-date with either our STEM or Professional monthly newsletters.
Arduino weekly newsletter (already subscribed)
Educators can benefit from the ever growing tech that shapes our environment through fun cool projects.
Why not awe your boss with highly innovative ways to help keep your enterprise connected at no extra cost?
Arduino Survey
We'd like to get to know you little better.
Please help us improve by answering this super short optional survey.