Let’s enjoy Arduino! LED With Button

By in Arduino, Programming on 2015年10月26日
void setup() {
  // put your setup code here, to run once:
  pinMode(7, OUTPUT);
  pinMode(2, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int buttonState = digitalRead(2);
  if (buttonState == HIGH) {
    digitalWrite(7, HIGH);
  } else {
    digitalWrite(7, LOW);
  }
}

Comments are closed.