Let’s enjoy Arduino! LED With Button 2

投稿者: カテゴリー: ArduinoProgramming オン 2015-11-15

Source Code is below.

int val = 0;
int state = 0;
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:
  val = digitalRead(2);

  if (val == HIGH) {
    state = 1 - state;
  }

  if (state == 1) {
    digitalWrite(7, HIGH);
  } else {
    digitalWrite(7, LOW);
  }
}

 

コメントは受け付けていません。