Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. const int buttonPinR = PUSH1;     // the number of the pushbutton pin
  2. const int buttonPinG = PUSH2;
  3. const int ledPinR =  3;
  4. const int ledPinG =  6;
  5.  
  6. // variables will change:
  7. int buttonState1 = 0;         // variable for reading the pushbutton status
  8. int buttonState2 = 0;
  9.  
  10. void setup() {
  11.   // initialize the LED pin as an output:
  12.   pinMode(ledPinR, OUTPUT);  
  13.   pinMode(ledPinG, OUTPUT);  
  14.   // initialize the pushbutton pin as an input:
  15.   pinMode(buttonPinR, INPUT_PULLUP);  
  16.   pinMode(buttonPinG, INPUT_PULLUP);
  17. }
  18.  
  19. void loop(){
  20.   // read the state of the pushbutton value:
  21.   buttonState1 = digitalRead(buttonPinR);
  22.   buttonState2 = digitalRead(buttonPinG);
  23.  
  24.   // check if the pushbutton is pressed.
  25.   // if it is, the buttonState is HIGH:
  26.   if (buttonState1 == LOW) {    
  27.     // turn LED on:    
  28.     digitalWrite(ledPinR, HIGH);  
  29.   }
  30.   else {
  31.     // turn LED off:
  32.     digitalWrite(ledPinR, LOW);
  33.   }
  34.    if (buttonState2 == LOW) {    
  35.     // turn LED on:    
  36.     digitalWrite(ledPinG, HIGH);  
  37.   }
  38.   else {
  39.     // turn LED off:
  40.     digitalWrite(ledPinG, LOW);
  41.   }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement