아두이노 스위치 입력 한번만 받기
2019. 7. 8. 16:12ㆍ드론
풀업 회로지만, 인버터 입력이 적용되어서 결과적으로 HIGH가 출력되는 스위치 회로
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int pinSwitch = 13; | |
int pinLed = 12; | |
int ledStatus = LOW; | |
int flag = 0; | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
pinMode(pinSwitch, INPUT); | |
pinMode(pinLed, OUTPUT); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
if(digitalRead(pinSwitch)) { | |
if(flag == 0) { | |
delay(20); | |
ledStatus = (ledStatus == LOW) ? HIGH : LOW; | |
digitalWrite(pinLed, ledStatus); | |
Serial.println("pushed"); | |
flag = 1; | |
delay(20); | |
} | |
} | |
else { | |
flag = 0; | |
Serial.println("pulled"); | |
} | |
} |
'드론' 카테고리의 다른 글
아두이노 Reed 자기 센서 제어 (0) | 2019.07.09 |
---|---|
아두이노로 FND 6자리 출력하기 (0) | 2019.07.08 |
아두이노 serialEvent 인터럽트 (0) | 2019.07.08 |
아두이노 LED 왕복해서 출력 (0) | 2019.07.08 |
아두이노 시리얼 모니터 새 줄과 line ending 없음 차이 (0) | 2019.07.08 |