Here's the context, I have a bluetooth module and when it is connected to a device the arduino reads that it is connected in the void loop(), once that statement becomes true (a device is connected) I want to make a motor spin, but only once, I don't want it to spin everytime the loop restarts and the statement is still true, BUT I can't put it in the void setup() because I want it to spin once something reconnects. I hope that makes sense; spin once connected, don't spin again until connection is made again. I am also trying to implement this in reverse as well, once there is a disconnection spin the motor the opposite way once, and doesn't spin again until there is another disconnection. I have very limited knowledge of arduino and don't even know how to describe the issue to find what I am looking for. Thanks for any and all help in advance!
do you have a sketch?
The trick is to save the old state in a variable. Determine if the thing is true and then compare to that old value and only act if it is true now and false last time. At the end of loop save the current value to the old value.
Have a look at the State Change Example that comes with the Arduino IDE. It solves this problem for a button press, but the approach will be the same.
1 Like
Omgosh that was exactly what I needed, it works perfectly! Thank you ya'll for trying and responding so quickly! Greatly appreciate it!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.