const int button = 11; // the number of the pushbutton pin const int LED = 10; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: pinMode(LED, OUTPUT); // initialize the pushbutton pin as an input: pinMode(button, INPUT); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(button); // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(LED, HIGH); } else { // turn LED off: digitalWrite(LED, LOW); } }
int buttonpin = 8; int yell = 11; int red = 10; int green = 9; int buttonstate = 0; void setup(){ pinMode(red, OUTPUT); pinMode(buttonpin, INPUT); pinMode(green, OUTPUT); pinMode(buttonpin, INPUT); pinMode(yell, OUTPUT); pinMode(buttonpin, INPUT); } void loop() { buttonstate = digitalRead(buttonpin); if (buttonstate == HIGH) { digitalWrite(red, LOW); digitalWrite(green, HIGH); digitalWrite(yell, HIGH); } else { digitalWrite(red, HIGH); digitalWrite(green, LOW); digitalWrite(yell, LOW); } }