I have an Arduino with an Adafruit motor shield as part of my robot. I want to start the engines at the same time when I play a tone on a piezoelectric element.
The problem is that I donβt quite know how to fake / simulate multitasking in my code. I tried something like this:
void goForward(int duration) { for (int i; i<duration; i++) { tl.run(FORWARD); tr.run(BACKWARD); bl.run(FORWARD); br.run(BACKWARD); counter++; if (counter%4==0) { piezo != piezo; } delay(1); } }
This starts the engines, however it does not create a tone on my piezoelectric element. What would be the best way to program this so that the piezo can be turned on / off at 440 Hz when the motor commands are working?
source share