// initialize digital pin LED_BUILTIN as an output. |
pinMode(LED_BUILTIN, OUTPUT); |
digitalWrite(LED_BUILTIN, HIGH); | // turn the LED on (HIGH is the voltage level) |
delay(1000); | // wait for a second |
digitalWrite(LED_BUILTIN, LOW); | // turn the LED off by making the voltage LOW |
delay(1000); | // wait for a second |
const byte PIN_LEDR = 5; | // Pin the Red LED is attached to (should be a PWM pin) |
// initialize digital pin PIN_LEDR as an output. |
pinMode(PIN_LEDR, OUTPUT); |
digitalWrite(PIN_LEDR, HIGH); | // turn the LED on (HIGH is the voltage level) |
delay(1000); | // wait for a second |
digitalWrite(PIN_LEDR, LOW); | // turn the LED off by making the voltage LOW |
delay(1000); | // wait for a second |
const byte PIN_LEDR = 5; | // Pin the Red LED is attached to (should be a PWM pin) |
// initialize digital pin PIN_LEDR as an output. |
pinMode(PIN_LEDR, OUTPUT); |
analogWrite(PIN_LEDR, 255); | // Set the Red LED brightness to 255 (full on) |
delay(500); | // wait half a second |
analogWrite(PIN_LEDR, 192); | // Set the Red LED brightness to 192 (75% on) |
delay(500); | // wait half a second |
analogWrite(PIN_LEDR, 128); | // Set the Red LED brightness to 128 (50% on) |
delay(500); | // wait half a second |
analogWrite(PIN_LEDR, 64); | // Set the Red LED brightness to 64 (25% on) |
delay(500); | // wait half a second |
analogWrite(PIN_LEDR, 0); | // Set the Red LED brightness to 0 (fully off) |
delay(1000); | // wait for a second |
const byte PIN_LEDR = 6; | // Pin the Red LED is attached to (should be a PWM pin) |
const byte PIN_LEDY = 9; | // Pin the Yellow LED is attached to (should be a PWM pin) |
const byte PIN_LEDG = 5; | // Pin the Green LED is attached to (should be a PWM pin) |
const byte PIN_BUT = 2; | // Pin the Button is connected to (button pressed=HIGH) |
// initialize LED pins as outputs |
pinMode(PIN_LEDR, OUTPUT); |
pinMode(PIN_LEDY, OUTPUT); |
pinMode(PIN_LEDG, OUTPUT); |
// initialize Button pin as input |
pinMode(PIN_BUT, INPUT); |
if (digitalRead(PIN_BUT)) { | // Check if the button is pressed |
digitalWrite(PIN_LEDR, HIGH); | // turn the Red LED on |
delay(500); | // wait 500 milli seconds (half a second) |
digitalWrite(PIN_LEDR, LOW); | // turn the Red LED off |
delay(500); | // wait 500ms |
} | |
digitalWrite(PIN_LEDG, HIGH); | // turn the Green LED on |
delay(500); | // wait 500ms |
digitalWrite(PIN_LEDG, LOW); | // turn the Green LED off |
delay(500); | // wait 500ms |
digitalWrite(PIN_LEDY, HIGH); | // turn the Yellow LED on |
delay(250); | // wait 250 milli seconds (a quarter of a second) |
digitalWrite(PIN_LEDY, LOW); | // turn the Yellow LED off |
delay(250); | // wait 250ms |
const byte PIN_LEDR = 6; | // Pin the Red LED is attached to (should be a PWM pin) |
const byte PIN_LEDY = 9; | // Pin the Yellow LED is attached to (should be a PWM pin) |
const byte PIN_LEDG = 5; | // Pin the Green LED is attached to (should be a PWM pin) |
const byte PIN_BUT = 2; | // Pin the Button is connected to (button pressed=HIGH) |
// initialize LED pins as outputs |
pinMode(PIN_LEDR, OUTPUT); |
pinMode(PIN_LEDY, OUTPUT); |
pinMode(PIN_LEDG, OUTPUT); |
// initialize Button pin as input |
pinMode(PIN_BUT, INPUT); |
int state_flash_r=0; | // Define a state variable for red LED |
int state_flash_y=0; | // Define a state variable for yellow LED |
int state_flash_g=0; | // Define a state variable for green LED |
if (state_flash_r==0 && !digitalRead(PIN_BUT)) return; | // We're waiting for the button, but it's up, so just bail out of function |
state_flash_r++; | // Increment state_flash_r, this is a short form of state_flash_r=state_flash_r+1 |
if (state_flash_r<20) { | // Time since button pressed is under 20*25=500ms |
digitalWrite(PIN_LEDR, HIGH); | // turn the Red LED on |
} else | |
if (state_flash_r<40) { | // Time since button pressed is under 40*25=1000ms |
digitalWrite(PIN_LEDR, LOW); | // turn the Red LED off |
} else { | |
// All done reset state | |
state_flash_r=0; | |
} |
state_flash_y++; | // Increment state_flash_y |
if (state_flash_y<10) { | // Time since start of state, is under 10*25=250ms |
digitalWrite(PIN_LEDY, HIGH); | // turn the Yellow LED on |
} else | |
if (state_flash_y<20) { | // Time since start of state, is under 20*25=500ms |
digitalWrite(PIN_LEDY, LOW); | // turn Yellow LED off |
} else { | |
// All done reset state | |
state_flash_y=0; | |
} |
state_flash_g++; | // Increment state_flash_g |
if (state_flash_g<20) { | // Time since start of state, is under 20*25=500ms |
digitalWrite(PIN_LEDG, HIGH); | // turn the Yellow LED on |
} else | |
if (state_flash_g<40) { | // Time since start of state, is under 40*25=1000ms |
digitalWrite(PIN_LEDG, LOW); | // turn Yellow LED off |
} else { | |
// All done reset state | |
state_flash_g=0; | |
} |
// Call all of the state update functions | |
do_flash_r(); | // Call the do_flash_r function |
do_flash_y(); | // Call the do_flash_y function |
do_flash_g(); | // Call the do_flash_g function |
delay(25); | // wait 25ms (1/40th of a second) |
const byte PIN_LEDR = 6; | // Pin the Red LED is attached to (should be a PWM pin) |
const byte PIN_LEDY = 9; | // Pin the Yellow LED is attached to (should be a PWM pin) |
const byte PIN_LEDG = 5; | // Pin the Green LED is attached to (should be a PWM pin) |
const byte PIN_BUT = 2; | // Pin the Button is connected to (button pressed=HIGH) |
// initialize LED pins as outputs |
pinMode(PIN_LEDR, OUTPUT); |
pinMode(PIN_LEDY, OUTPUT); |
pinMode(PIN_LEDG, OUTPUT); |
// initialize Button pin as input |
pinMode(PIN_BUT, INPUT); |
int state_flash_r=0; | // Define a state variable for red LED |
int state_flash_g=0; | // Define a state variable for green LED |
if (state_flash_r==0 && !digitalRead(PIN_BUT)) return; | // We're waiting for the button, but it's up, so just bail out of function |
state_flash_r++; | // Increment state_flash_r, this is a short form of state_flash_r=state_flash_r+1 |
if (state_flash_r<20) { | // Time since button pressed is under 20*25=500ms |
digitalWrite(PIN_LEDR, HIGH); | // turn the Red LED on |
} else | |
if (state_flash_r<40) { | // Time since button pressed is under 40*25=1000ms |
digitalWrite(PIN_LEDR, LOW); | // turn the Red LED off |
} else { | |
// All done reset state | |
state_flash_r=0; | |
} |
analogWrite(PIN_LED_Y, random(20, 255)); | // Set the Yellow LED to random brightness 20...255 |
state_flash_g++; | // Increment state_flash_g |
if (state_flash_g<256) { | // Fading up |
analogWrite(PIN_LED_G, state_flash); | // Set the Green LED to fade up level |
} else | |
if (state_flash_g<512) { | // Fading down |
analogWrite(PIN_LED_G, 511-state_flash_g); | // Set the Green LED to fade down level |
} else { | |
// All done reset state | |
state_flash_g=0; | |
} |
do_flash_r(); | // Call the do_flash_r function |
do_flash_y(); | // Call the do_flash_y function |
do_flash_g(); | // Call the do_flash_g function |
delay(25); | // wait 25ms (1/40th of a second) |