Hello! I am very out of practice with programming. I am trying to prototype a robot Halloween costume for my almost 3 yr old. I have adapted the sketch by mikalhart found here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1225593807
I have adapted the number of LEDs and the rates of flash (but I am pretty much using his code) I love the idea that I can alter the blink of each in the array, but I am unsure of where to go next.
If nobody cares to click, I will post the sample code below.
I would also love to have a servo sweep simultaneously (like an antenna or some other robot type device), but I am clueless as to how to implement this.
I have tried to simply cut and paste the servo sweep example into this sample code, and as many of you could imagine, the introduction of delay means the LEDs blink THEN the servo sweeps.
My original thought was to implement a ping sensor to "turn on" the costume (or off) at a certain distance, but I am lost and will graciously accept any help. I have played with some other examples including the ping sensor (like parking assistants) that turn on LEDs, but blinky and servo are more important to the wife than proximity sensors.
I thank you for reading! I am quite lost, so be gentle.
Thanks!
-e
Mikal's code:
/* Blink Multiple LEDs without Delay
*
* Turns on and off several light emitting diode(LED) connected to a digital
* pin, without using the delay() function. This means that other code
* can run at the same time without being interrupted by the LED code.
*/
int led1 = 13; // LED connected to digital pin 13
int led2 = 12;
int value1 = LOW; // previous value of the LED
int value2 = LOW; // previous value of the LED
long time1 = millis();
long time2 = millis();
long interval1 = 1000; // interval at which to blink (milliseconds)
long interval2 = 500;
void setup()
{
pinMode(led1, OUTPUT); // sets the digital pin as output
pinMode(led2, OUTPUT);
}
void loop()
{
unsigned long m = millis();
if (m - time1 > interval1){
time1 = m;
if (value1 == LOW)
value1 = HIGH;
else
value1 = LOW;
digitalWrite(led1, value1);
}
if (m - time2 > interval2){
time2 = m;
if (value2 == LOW)
value2 = HIGH;
else
value2 = LOW;
digitalWrite(led2, value2);
}
}