|
发表于 2014-10-20 22:03:06
|
显示全部楼层
本帖最后由 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.
|
|