hi !
we are creating a drawing machine that does mistakes and turns red (LED) after the mistake.
This is the code so far :
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
#include <Servo.h>
Servo servoMain; // Define our Servo
Servo servo2;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
servo2.attach(9);
servoMain.attach(10);
}
// the loop routine runs over and over again forever:
void loop() {
turnRight (); // Turn Servo Left to 45 degrees
delay(3000);
servo2.write(0);
delay(1000);
servo2.write(20);
delay(1000);
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
delay(2000); // wait for a second
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
void turnRight() {
servoMain.write(180);
}
But right now, the Servomain is doing a circle (this is what we want) and the Servo2 is moving sometimes : it is the mistake. However, we do not now how to make the light on after the mistake for a few seconds and then off again before the next mistake. Also, what would be awesome is if we could have the mistake randomly.
Thanks for your help !
check this out.
So you basically wants to get rid of the delays, wich make your whole code to wait.
See this: https://learn.adafruit.com/multi-tasking-the-arduino-part-1/using-millis-for-timing