Skip to content

Commit

Permalink
BlinkPWM_loop_3inputs pulses an LED from Min (0) to Max (255) and bac…
Browse files Browse the repository at this point in the history
…k again, repeatedly. Speed controlled by 3 inputs.

BlinkPWM_loop_3inputs pulses an LED from Min (0) to Max (255) and back
again, repeatedly. Speed controlled by 3 inputs.
  • Loading branch information
raspitv committed Apr 20, 2015
1 parent 20b406a commit 2acbd4b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions BlinkPWM_loop_3inputs/BlinkPWM_loop_3inputs.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
BlinkPWM_loop_3inputs pulses an LED from Min (0) to Max (255)
and back again, repeatedly. Speed controlled by 3 inputs.
*/

int led = 5; // name our PWM pin:
int time_delay = 8; // set time delay (mS) duration here
int input_value = 1; // set our initial input value

void setup() {
pinMode(led, OUTPUT); // set pin as output
for (int thisPin = 6; thisPin < 9; thisPin++) {
pinMode(thisPin, INPUT); // set pins 6-8 as inputs
}
}

void loop() {
time_delay = 8; // set default delay
for (int thisPin = 6; thisPin < 9; thisPin++) {
input_value = digitalRead(thisPin); // read input pin
if (input_value == 1) { // if it's HIGH
time_delay /= 2; // set delay to half
}
}
// fade led pin from off (0) to brightest (255)
for (int brightness = 0; brightness < 255; brightness++) {
analogWrite(led, brightness);
delay(time_delay);
}
// fade led pin from brightest (255) to off (0)
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(led, brightness);
delay(time_delay);
}
}

0 comments on commit 2acbd4b

Please sign in to comment.