I am a beginner to the Arduino environment and I am trying to build a small prototype for underwater ROV.
I have been researching online to find out how I can control LED lights and a motor simultaneously with Arduino, by applying the commands via laptop keyboard. However, I couldn't find what I wanted.
I am able to run the two sketches separately, but when I combine them together I need to click a key several times before the motors start/stop or the LEDs are on/off. So it does not happen with one click.
I imagine this has something to do with the data that Arduino reads when I press the buttons (it probably goes from 0 to 1 and the opposite).
Is there any example of how control two different things at the same time using the keyboard?
pzas21:
I am able to run the two sketches separately, but when I combine them together I need to click a key several times before the motors start/stop or the LEDs are on/off. So it does not happen with one click.
You need to post your program so we can see exactly what you are doing.
I agree with Reply #3. I think it is also pretty much essential to send the two values (lights and motor) at the same time so the Arduino always knows which one is which. If you send them separately they could get mixed up. This may mean sending the same value over and over if it does not change.
slipstick:
It might make more sense to read the value from Serial once at the top of loop() and THEN call routines which just deal with whatever has arrived.
Steve
Hi Steve,
Thanks for the reply. I will implement the change as advised.
Robin2:
I agree with Reply #3. I think it is also pretty much essential to send the two values (lights and motor) at the same time so the Arduino always knows which one is which. If you send them separately they could get mixed up. This may mean sending the same value over and over if it does not change.
…R
Hi Robin, thanks that as well.
I think I found a solution for working simultaneously. Maybe it is not the most appropriate one but it seems to work. I just combined both lights and motor in one function and used switch() { case:… break;} for applying every case that I am looking to have and it is working good!