one goes on for 500 milliseconds and then goes off for 500 milliseconds
another goes on after 30 seconds and stays on for the next 30 seconds
another goes on after 60 minutes and stays on for the next 60 minutes
any way its fine heres my code:
uint32_t
time_now = 0,
time_past = 0;
uint8_t
half_seconds = 0,
seconds = 0,
minutes = 0,
LED_seconds_pin = 11,
LED_minutes_pin = 12,
LED_hours_pin = 13;
bool
LED_seconds_state = false,
LED_minutes_state = false,
LED_hours_state = false;
void setup()
{
pinMode( LED_seconds_pin, OUTPUT );
pinMode( LED_minutes_pin, OUTPUT );
pinMode( LED_hours_pin, OUTPUT );
time_past = millis();
}
void loop()
{
time_now = millis();
//every 500 milliseconds
if ( time_now - time_past >= 500 )
{
time_past = time_now;
//toggle LED_seconds
LED_seconds_state = !LED_seconds_state;
digitalWrite( LED_seconds_pin, LED_seconds_state );
//every seconds
if ( ++ half_seconds >= 2 )
{
half_seconds = 0;
//every 30 seconds
if ( ++ seconds >= 60 )
{
seconds = 0;
//toggle LED_minutes
LED_minutes_state = !LED_minutes_state;
digitalWrite( LED_minutes_pin, LED_minutes_state );
//every 30 minutes
if ( ++ minutes >= 30 )
{
minutes = 0;
//toggle LED_hours
LED_hours_pin = !LED_hours_pin;
digitalWrite( LED_hours_pin, LED_hours_state );
}
}
}
}
}
thanks!