Hello! I am middle school teacher fumbling my way through learning how to use Arduino in order to help a student of mine learn to create a specific project she has in mind. I am SO new to this, I don't even know what I don't know. We have exactly one week to get this figured out, and I don't want to disappoint her! She wants to program her LEDs to do this:
LED1: flash on for one second, turn off for 15 seconds, and then repeat indefinitely.
LED2: flash on for one second, turn off for 16 seconds, and then repeat indefinitely.
LED3: flash on for one second, turn off for 7.5 minutes, and then repeat indefinitely.
LED4: flash on for one second, turn off for 1 second, and then repeat indefinitely.
LED5: flash on for one second, turn off for 48 seconds, and then repeat indefinitely.
LED6: flash on for one second, turn off for 50 seconds, and then repeat indefinitely.
She has successfully managed to make them blink like this (which is NOT what she wants):
LED1: flash on for 15 second, turn off for 15 seconds, and then repeat indefinitely.
LED2: flash on for 16 second, turn off for 16 seconds, and then repeat indefinitely.
LED3: flash on for 7.5 minutes, turn off for 7.5 minutes, and then repeat indefinitely.
LED4: flash on for one second, turn off for 1 second, and then repeat indefinitely.
LED5: flash on for 48 seconds, turn off for 48 seconds, and then repeat indefinitely.
LED6: flash on for 50 seconds, turn off for 50 seconds, and then repeat indefinitely.
using the code below, but we can't manipulate the code correctly to make this one small change! It's making me crazy! Can anyone help?
// Which pins are connected to which LED
const byte LED1 = 6;
const byte LED2 = 7;
const byte LED3 = 8;
const byte LED4 = 9;
const byte LED5 = 10;
const byte LED6 = 11;
// Assigning delays.
const unsigned long LED1_ON_interval = 15000; //
const unsigned long LED1_OFF_interval = 15000;
const unsigned long LED2_ON_interval = 16000; //
const unsigned long LED2_OFF_interval = 16000;
const unsigned long LED3_ON_interval = 450000; //
const unsigned long LED3_OFF_interval = 450000;
const unsigned long LED4_ON_interval = 1000; //
const unsigned long LED4_OFF_interval = 1000;
const unsigned long LED5_ON_interval = 48000; //
const unsigned long LED5_OFF_interval = 48000;
const unsigned long LED6_ON_interval = 50000; //
const unsigned long LED6_OFF_interval = 50000;
// Declaring the variables holding the timer values for each LED.
unsigned long LED1_timer;
unsigned long LED2_timer;
unsigned long LED3_timer;
unsigned long LED4_timer;
unsigned long LED5_timer;
unsigned long LED6_timer;
// Setting 3 digital pins as output pins and resetting timer
void setup ()
{
pinMode (LED1, OUTPUT);
pinMode (LED2, OUTPUT);
pinMode (LED3, OUTPUT);
pinMode (LED4, OUTPUT);
pinMode (LED5, OUTPUT);
pinMode (LED6, OUTPUT);
LED1_timer = millis ();
LED2_timer = millis ();
LED3_timer = millis ();
LED4_timer = millis ();
LED5_timer = millis ();
LED6_timer = millis ();
} // end of setup
//LED1 loop that turns it ON if it is OFF and vice versa
void toggle_LED1 ()
{
if (digitalRead (LED1) == LOW)
digitalWrite (LED1, HIGH);
else
digitalWrite (LED1, LOW);
// remember when we toggled it
LED1_timer = millis ();
} // end of toggleLED_1
//LED2 loop
void toggle_LED2 ()
{
if (digitalRead (LED2) == LOW)
digitalWrite (LED2, HIGH);
else
digitalWrite (LED2, LOW);
// remember when we toggled it
LED2_timer = millis ();
} // end of toggle_LED2
//LED 3 loop
void toggle_LED3 ()
{
if (digitalRead (LED3) == LOW)
digitalWrite (LED3, HIGH);
else
digitalWrite (LED3, LOW);
// remember when we toggled it
LED3_timer = millis ();
} // end of toggle_LED3
void toggle_LED4 ()
{
if (digitalRead (LED4) == LOW)
digitalWrite (LED4, HIGH);
else
digitalWrite (LED4, LOW);
// remember when we toggled it
LED4_timer = millis ();
} // end of toggleLED_4
//LED2 loop
void toggle_LED5 ()
{
if (digitalRead (LED5) == LOW)
digitalWrite (LED5, HIGH);
else
digitalWrite (LED5, LOW);
// remember when we toggled it
LED5_timer = millis ();
} // end of toggle_LED5
//LED 3 loop
void toggle_LED6 ()
{
if (digitalRead (LED6) == LOW)
digitalWrite (LED6, HIGH);
else
digitalWrite (LED6, LOW);
// remember when we toggled it
LED3_timer = millis ();
} // end of toggle_LED6
void loop ()
{
// Handling the blink of LED1.
if ( (millis () - LED1_timer) >= LED1_ON_interval)
toggle_LED1 ();
// Handling the blink of LED1.
if ( (millis () - LED1_timer) >= LED1_OFF_interval)
toggle_LED1 ();
// Handling the blink of LED2.
if ( (millis () - LED2_timer) >= LED2_ON_interval)
toggle_LED2 ();
if ( (millis () - LED2_timer) >= LED2_OFF_interval)
toggle_LED2 ();
// Handling the blink of LED3.
if ( (millis () - LED3_timer) >= LED3_ON_interval)
toggle_LED3 ();
// Handling the blink of LED4.
if ( (millis () - LED4_timer) >= LED4_ON_interval)
toggle_LED4 ();
// Handling the blink of LED5.
if ( (millis () - LED5_timer) >= LED5_ON_interval)
toggle_LED5 ();
// Handling the blink of LED6.
if ( (millis () - LED6_timer) >= LED6_ON_interval)
toggle_LED6 ();
/* Other code that needs to execute goes here.
It will be called many thousand times per second because the above code
does not wait for the LED blink interval to finish. */
} // end of loop