Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust our Boolean flip-flop, to use pull-ups
Adjust our Boolean flip-flop, to use pull-ups to avoid spurious input signals. We have to invert our logic as well.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
flip_flop_with_3inputs_boolean_pull/flip_flop_with_3inputs_boolean_pull.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Adjust our Boolean flip-flop, to use pull-ups to avoid | ||
spurious input signals. We have to invert our logic as well. | ||
*/ | ||
|
||
int led = 13; // set pin 13 LED variable name | ||
int newled = 5; // add our second LED on pin 5 | ||
int time_delay = 500; // set time delay (mS) duration here | ||
|
||
void setup() { | ||
pinMode(led, OUTPUT); // set up LED pin 13 as output | ||
pinMode(newled, OUTPUT); // set second LED pin 5 as output | ||
pinMode(8, INPUT_PULLUP); // set up pin 8 as an input + pullup | ||
pinMode(7, INPUT_PULLUP); // set up pin 7 as an input + pullup | ||
pinMode(6, INPUT_PULLUP); // set up pin 6 as an input + pullup | ||
} | ||
|
||
// the loop routine runs over and over again forever: | ||
void loop() { | ||
// if any pin 6 or 7 or 8 is LOW | ||
// notice the ! in front of each Read to "not" it | ||
if (! digitalRead(6) || ! digitalRead(7) || ! digitalRead(8)) { | ||
time_delay = 250; // set delay to 250 | ||
} | ||
else { | ||
time_delay = 1000; // set (default delay) | ||
} | ||
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 | ||
} |