我正在试着做一个开关来打开一个带上推按钮的LED,我尝试了很多方法,最后想出了这个:
int boton_en=0;
int parar=0;
void setup() {
// put your setup code here, to run once:
pinMode(4, OUTPUT);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
boton_en = digitalRead(8);
if (boton_en == LOW){
parar = 1 - parar;
}
if (parar == 1){
digitalWrite(4,HIGH);
}else{
digitalWrite(4,LOW);
}
}
第一次按下按钮后,LED亮起,但任何连续按下都不会关闭它。任何帮助/评论都会有所帮助。:)
转载请注明出处:http://www.0730huitian.com/article/20230526/2606424.html