Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int buttonPinR = PUSH1; // the number of the pushbutton pin
- const int buttonPinG = PUSH2;
- const int ledPinR = 3;
- const int ledPinG = 6;
- // variables will change:
- int buttonState1 = 0; // variable for reading the pushbutton status
- int buttonState2 = 0;
- void setup() {
- // initialize the LED pin as an output:
- pinMode(ledPinR, OUTPUT);
- pinMode(ledPinG, OUTPUT);
- // initialize the pushbutton pin as an input:
- pinMode(buttonPinR, INPUT_PULLUP);
- pinMode(buttonPinG, INPUT_PULLUP);
- }
- void loop(){
- // read the state of the pushbutton value:
- buttonState1 = digitalRead(buttonPinR);
- buttonState2 = digitalRead(buttonPinG);
- // check if the pushbutton is pressed.
- // if it is, the buttonState is HIGH:
- if (buttonState1 == LOW) {
- // turn LED on:
- digitalWrite(ledPinR, HIGH);
- }
- else {
- // turn LED off:
- digitalWrite(ledPinR, LOW);
- }
- if (buttonState2 == LOW) {
- // turn LED on:
- digitalWrite(ledPinG, HIGH);
- }
- else {
- // turn LED off:
- digitalWrite(ledPinG, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement