Reputation: 75
I have an Arduino Uno and an Arduino Nano communicating successfully via XBee Series 1 radios.
A light sensor is attached to Arduino Uno, reading and uploading light intensity data to another XBee radio attached to my PC. An LED (which is modelling after a relay), is attached the Arduino Uno.
I am thinking of activating this relay wirelessly through XBee whenever a button is pressed on the Arduino Nano, and I have thought of using the attachInterrupt() function in Arduino. This is because there is a 1s delay in void loop() but I would like to have the relay activated instantaneously whenever I press a button on the Arduino Nano.
May I ask if the attachInterrupt() function will work if I were to send data wirelessly from the XBee on Arduino Nano to my Uno?
Thank you! :)
Upvotes: 0
Views: 349
Reputation: 144
Simply based on your idea, I recommend not to implement all the relay operation in the interrupt function. Normally, interrupt handler would manage only essential parts which can be done shortly without any pending operation. Otherwise, the operation would block the following interrupts handling. Therefore, you'd better declare a flag to detect the button event and check this flag in your loop operation to send the data to PC.
However, this flag would be wrongly referred to due to race-condition. If you need to have more consistent detection, then you'd better follow some examples from Task library. I think you might have an interest in the examples such as ButtonInterrupt and MessageTask.
Upvotes: 0