CODE 5.8 | 풀다운 저항 방식으로 버튼 상태 읽기
| 01 | int buttonPin = 2; // 푸시 버튼을 연결한 디지털 핀 |
| 02 | |
| 03 | void setup() { |
| 04 | Serial.begin(9600); // 시리얼 모니터 통신 시작 |
| 05 | pinMode(buttonPin, INPUT); // 버튼 핀을 입력 모드로 설정 |
| 06 | } |
| 07 | |
| 08 | void loop() { |
| 09 | int buttonState = digitalRead(buttonPin); // 버튼 상태 읽기 |
| 10 | |
| 11 | Serial.println(buttonState); // 읽은 값을 시리얼 모니터에 출력 |
| 12 | |
| 13 | delay(100); // 0.1초 대기 후 다시 측정 |
| 14 | } |
댓글 없음:
댓글 쓰기