首页 > 其他分享 >arduino中断

arduino中断

时间:2022-10-17 23:37:45浏览次数:69  
标签:LED arduino 中断 void state TEST Serial define


[codesyntax lang="cpp" lines="normal"]


#define LED 13 #define PIN 2 #define TEST 3 volatile int state = LOW; void setup() { Serial.begin(9600); pinMode(LED, OUTPUT); pinMode(TEST, OUTPUT); attachInterrupt(0, stateChange, CHANGE); } void loop() { int v = digitalRead(PIN); Serial.println(v); delay(500); } void stateChange() { Serial.println("======="); state = !state; digitalWrite(LED, state); if(state) { analogWrite(TEST, 10); } else { analogWrite(TEST, 0); } }


[/codesyntax]

 

备注:

  • 根据本人实验,MJDuino UNO版本有时回因为中断函数的调用导致程序停止运行。


标签:LED,arduino,中断,void,state,TEST,Serial,define
From: https://blog.51cto.com/suren/5764665

相关文章