Arduino

Switch 상태를 UART로 확인하기

작성자 임베디드코리아 작성일25-05-15 17:21 조회172회 댓글0건

첨부파일

<* Switch 상태를 UART로 확인하기 *>
- Switch를 D8에 연결하고, Serial Monitor로 Switch 상태를 확인한다.
- Switch를 "OFF"가 출력도다가, 누르면 "ON"이 출력된다
----------------------------------------------------------------
const int switch_Pin = 8;
bool read_switch;

void setup() {
  Serial.begin(9600);
  pinMode(switch_Pin, INPUT);
}

void loop() {
    read_switch = digitalRead(switch_Pin); 
    if(read_switch){
        Serial.write("ON\n");
        delay(500);
      }else{
        Serial.write("OFF\n");
        delay(500);
      }
}