HW2_PUSHBUTTON&LEDS_YU_ZHANG

20140912131310

 

Push Button -> LEDS

Seven green flashing LEDs controlled by one pushbutton.

All seven green flashing LEDs were connected on another breadboard.

Each time I push the button, the flashing LEDs will stop flashing.

————————————————

CODE:

int buttonPin = 2;
int ledPin = 9;
int buttonState = 0;
void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}
void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW) {
    digitalWrite(ledPin, HIGH);
    delay(50);
    digitalWrite(ledPin, LOW);
    delay(50);
  }
  else {
    digitalWrite(ledPin, LOW);
  }
}

Leave a Reply

Your email address will not be published.