Question

I currently have two Arduinos talking to one another via Xbees and I was hoping to get some feedback as I've been looking for an answer to this question.

I'm aiming to have things setup so that when a flex sensor goes above a certain number on Arduino 1, it sets off 2 minute sequence of lights fading on and off, gradually getting dimmer and dimmer after each on/off fade on Arduino 2. I'm slightly unsure of the code on how to do this, but I figure it can be done modifying the fade code to remember the last maximum number, and for the next time decrease it by 1.

However... while this sequence is underway, I want it to be cancelled by bending the flex sensor on Arduino 2. I'm aiming for the Arduino to react to nothing else while this light sequence is going other than it's own flex sensor, meaning the flex sensor on Arduino 1 doesn't restart another sequence if it is bend to the set value or above WHILE the light sequence is underway. Once this flex sensor has been bent, the ideal scenario would be that the light sequence is cancelled or ended, and replica light sequence is started on Arduino 1.

I'm hoping for advice on the code to do this, and also if it's possible to have an interrupt of this nature? I'm sorry if this is covered elsewhere, but I've been struggling to find it.

Was it helpful?

Solution

This is my understanding:

Arduino 1's flex sensor is bent -> Arduino 2 starts a light show
Arduino 2's flex sensor is bent -> Arduino 2 stops light show, Arduino 1 starts a new light show.

Solution:

While Arduino 2 is running its light show loop have it check its flex sensor each time it loops. Break out of the loop if the flex sensor shows a bend. Once out of the loop, have it signal Arduino 1 to commence its own light show. Just ignore any input (i.e. do not check for input) from Arduino 1 while Arduino 2 is running its light show.

EDIT: Depending on how long your loop is, you might want to check the flex sensor more than once in the loop

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top