1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#define BTN_PIN         5               // 버튼 연결 Pin 번호
#define BTN_LED_PIN     4               // 버튼 LED 연결 Pin 번호
#define DIODE_LED_PIN   3               // 다이오드 LED 연결 Pin 번호
 
bool enable = false;
 
void setup() {
  Serial.begin(115200);
 
  pinMode(BTN_PIN, INPUT);              // 버튼 Pin을 입력모드로 설정
  pinMode(BTN_LED_PIN, OUTPUT);         // 버튼 LED Pin을 출력모드로 설정
  pinMode(DIODE_LED_PIN, OUTPUT);       // 다이오드 LED Pin을 출력모드로 설정
}
 
void loop() {
  if(digitalRead(BTN_PIN) == HIGH){                   // 버튼 클릭 상태일 때,
      while(digitalRead(BTN_PIN) == HIGH){                // 버튼이 클릭이 종료될 때까지 대기.
        delay(100);
      }
      enable = !enable;                               // 다이오드 LED 상태 전환 
  }
 
  digitalWrite(DIODE_LED_PIN, enable);                // 다이오드 LED 상태 설정  
  digitalWrite(BTN_LED_PIN, !enable);                 // 다이오드 LED 상태와 반대로 버튼 LED 상태 제어
  
  delay(50);
}
cs

 

+ Recent posts