我是Arduino的初学者。我想用2块Arduino Mega板控制64个LED。
逻辑是:
asm volatile("jmp 0")
重置两个Arduinos。我使用引脚52作为TX,将引脚53作为RX使用。
现在的问题是,在Arduino 1完成闪烁并向Arduino 2发出信号(HIGH)后,它不会等待来自Arduino 2的信号,而是自行重置。
任何人都可以查看我的代码,看看它是逻辑错误还是编码错误?
digitalWrite(TX, HIGH);
delay(1000);
if(digitalRead(RX)==HIGH) {
asm volatile("jmp 0");
}
答案 0 :(得分:0)
digitalWrite(TX, HIGH);
delay(1000);
if(digitalRead(RX)==HIGH) {
asm volatile("jmp 0");
}
执行此操作时,您必须确保Arduino 2在使用LED之前先将其TX引脚设置为LOW。只有当它完成时,才应将其TX引脚设置为高电平。
答案 1 :(得分:0)
您需要将关闭序列互锁:
// Arduino 1:
digitalWrite(TX, HIGH); // set high for 1 second
delay(1000);
while (digitalRead(RX)) // wait for a low pulse from # 2
;
digitalWrite(TX, LOW); // #2 is latched.
while (!digitalRead(RX))
;
// RX is high again, #2 is ready to reset as well...
asm volatile("jmp 0");
// arduino # 2, assuming you have already detected a pulse longer than 500ms on RX,
// sequence:
digitalWrite(TX, LOW); // indicate we're latched
while(digitalRead(RX)) // wait for end of pulse from #1
;
digitalWrite(TX, HIGH); // indicate we're ready
delay(2); // make sure #1 gets it.
asm volatile("jmp 0"); // reset at approx same time as #1
Arduino#2应该在其忙碌时保持其TX线为高电平,并希望延迟复位。