Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- }
- if (digitalRead(buttonPin2) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
- {digitalWrite(ledPin2, LOW); // turn ledPin2 on
- ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
- }
- // set pins
- const int buttonPin1 = 2; // Pin1's pushbutton
- const int buttonPin2 = 4; // Pin2's pushbutton
- const int buttonPin3 = 6; // Pin3's pushbutton
- const int buttonPin4 = 8; // Pin4's pushbutton
- const int ledPin1 = 3; // Pin1's LED
- const int ledPin2 = 5; // Pin2's LED
- const int ledPin3 = 7; // Pin3's LED
- const int ledPin4 = 9; // Pin4's LED
- // set variables
- int ledPin1_status = 0;
- int ledPin2_status = 0;
- int ledPin3_status = 0;
- int ledPin4_status = 0;
- void setup() { //initialize pins
- pinMode(buttonPin1, INPUT); // set PINn as INPUT
- pinMode(buttonPin2, INPUT);
- pinMode(buttonPin3, INPUT);
- pinMode(buttonPin4, INPUT);
- pinMode(ledPin1, OUTPUT); // set LEDn as OUTPUT
- pinMode(ledPin2, OUTPUT);
- pinMode(ledPin3, OUTPUT);
- pinMode(ledPin4, OUTPUT);
- }
- // the following variables are unsigned longs because the time, measured in
- // milliseconds, will quickly become a bigger number than can be stored in an int.
- unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
- unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
- void loop() {
- if (digitalRead(buttonPin1) == HIGH) { // check if buttonPin1 was pressed (be sure to use a resistor?)
- if (ledPin1_status == 0) { // check if ledPin1 was not already pressed
- digitalWrite(ledPin1, HIGH); // turn ledPin1 on
- ledPin1_status = 1; // 1 = on, set ledPin1_status to 1
- }
- else {
- digitalWrite(ledPin1, LOW); // turn ledPin1 off
- ledPin1_status = 0; // 0 = off, set Pin1_status to 0
- digitalWrite(ledPin2, LOW); // turn ledPin2 off
- ledPin2_status = 0; // 0 = off, set Pin2_status to 0
- digitalWrite(ledPin3, LOW); // turn ledPin3 off
- ledPin3_status = 0; // 0 = off, set Pin2_status to 0
- digitalWrite(ledPin4, LOW); // turn ledPin4 off
- ledPin3_status = 0; // 0 = off, set Pin2_status to 0
- }
- }
- if (digitalRead(buttonPin2) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
- {digitalWrite(ledPin2, HIGH); // turn ledPin2 on
- ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
- }
- }
- if (digitalRead(buttonPin2) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
- {digitalWrite(ledPin2, LOW); // turn ledPin2 on
- ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
- }
- }
- if (digitalRead(buttonPin3) == HIGH) { // check if buttonPin3 was pressed (be sure to use a resistor?)
- {digitalWrite(ledPin3, HIGH); // turn ledPin3 on
- ledPin3_status = 1; // 1 = on, set ledPin3_status to 1
- }
- }
- if (digitalRead(buttonPin3) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
- {digitalWrite(ledPin3, LOW); // turn ledPin3 on
- ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
- }
- }
- if (digitalRead(buttonPin4) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
- {digitalWrite(ledPin4, HIGH); // turn ledPin4 on
- ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
- }
- }
- if (digitalRead(buttonPin4) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
- {digitalWrite(ledPin4, LOW); // turn ledPin4 on
- ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
- }
- }
Add Comment
Please, Sign In to add comment