Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Jung Min Yean
- * 03/25/19
- * Program about turning on and off one LED with a button
- *
- */
- // Declare Constants and variables
- const byte Button=9;
- const byte LedPin=17;
- byte ReadVal; // variable to read button
- const byte LedPin2 = 19;
- int count=0;
- void setup() {
- pinMode(LedPin, OUTPUT);
- pinMode(LedPin2, OUTPUT);
- pinMode(Button, INPUT);
- Serial.begin(9600);
- }
- void loop() {
- ReadVal = digitalRead(Button); //when on the ReadVal should be 1 and off should be 0, otherwise it is not being read
- delay(10);
- //Serial.println(ReadVal);
- if(ReadVal ==1) // == is asking if the variable has a value of 1
- {
- count ++;
- }
- if (count == 1)
- {
- digitalWrite(LedPin, HIGH);
- digitalWrite(LedPin2, LOW);
- }
- else if(count == 2)
- {
- digitalWrite(LedPin2, HIGH);
- digitalWrite(LedPin, LOW);
- count = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement