如何用一个arduino触发另一个arduino的中断
本帖最后由 openmmoo 于 2014-10-27 14:31 编辑菜鸟一个,问题如题:如何用一个arduino触发另一个arduino的中断,求连接图! 本帖最后由 Super169 于 2014-10-20 22:04 编辑
兩板共地後, 用一根線一邊接 int I/O (例如 D2), 另一邊接另一塊的數字 I/O.
接數字 I/O 的一塊用 DigitalWrite 改變設定, 而接 int I/O 的一塊就針對需要的狀態設定 interrupt 程式.
例如兩板都接上 D2, 主動的一塊執行以下程式:
#define OUT_PIN 2
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
pinMode(OUT_PIN, OUTPUT);
digitalWrite(OUT_PIN, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Set HIGH");
digitalWrite(OUT_PIN, HIGH);
delay(2000);
Serial.println("Set LOW");
digitalWrite(OUT_PIN, LOW);
delay(2000);
}
被動的一塊執行以下程式:
int cnt = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
attachInterrupt(0, isr_change, CHANGE);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(cnt);
delay(500);
}
void isr_change() {
cnt++;
}
每次改變, 就會觸發isr_change, 把 cnt 的數值 +1.
页:
[1]