About Us About Embedded Introduce Editorial Contributions Location Document Android Application Embedded Linux Processor Arduino AVR Devices Resource Android Application Embedded Linux Processor Arduino AVR Devices Education 교육과정안내 교재 프로젝트 자료실 Reference Community 공지사항 제품광고 구인광고
디지털 센서 인터럽트 사용하기 작성자 임베디드코리아 작성일25-05-15 23:38 조회160회 댓글0건 첨부파일 Interrupt_LED.ino (336byte) 0회 다운로드 DATE : 2025-05-16 15:40:38 이전글 다음글 목록 <* 인터럽트를 이용한 디지털 센서 사용하기 *> - 충격 센서와 같이 순간적으로만 반응하면 센서값을 읽기가 얼렵다 - 인터럽트기능 이용하여 순간적으로 변한 값에 반응하게 하여 LED를 On/Off 해본다. ----< 인터럽트를 이용한 소스 코드 >------------------------------------ 1) D2에 Switch를 달아서 스위치로 반응 시킨다. - 충격 센서가 있으면 달아준다 2) D13에 LED를 달아 준다 const byte ledPin = 13; const byte interruptPin = 2; volatile byte state = LOW; void setup() { pinMode(ledPin, OUTPUT); pinMode(interruptPin, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE); } void loop() { digitalWrite(ledPin, state); } void blink() { state = !state; } 이전글 다음글 목록