-
Notifications
You must be signed in to change notification settings - Fork 5
/
flip_flop_with_3inputs_loop.ino
40 lines (37 loc) · 1.55 KB
/
flip_flop_with_3inputs_loop.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Adjust our flip-flop, so that when pin 8, 7 or 6 is HIGH
the flashing is faster and when pin 8, 7 or 6 LOW it's slower
Added loops to reduce repetitive code
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
int newled = 5; // add our second LED on pin 5
int time_delay = 500; // set time delay (mS) duration here
int input_value = 1; // set our initial input value
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(newled, OUTPUT); // set up our second LED as output
for (int thisPin = 6; thisPin < 9; thisPin++) {
pinMode(thisPin, INPUT); // set pins 6-8 as inputs
}
}
// the loop routine runs over and over again forever:
void loop() {
time_delay = 1000; // set delay to 1000 ms
// loop through pins starting at 6 and stopping at 8
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
}
}
digitalWrite(led, HIGH); // turn LED ON (HIGH is the voltage level)
digitalWrite(newled, LOW); // turn newLED OFF (LOW is the voltage level)
delay(time_delay); // wait for time_delay
digitalWrite(led, LOW); // turn LED OFF by making the voltage LOW
digitalWrite(newled, HIGH); // turn LED ON by making the voltage HIGH
delay(time_delay); // wait for time_delay
}