Created
August 9, 2013 18:14
-
-
Save geckotang/6195804 to your computer and use it in GitHub Desktop.
押した色に対応した色のLEDが付く
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LEDが接続されているピン | |
const int LED_1 = 13; // YELLOW | |
const int LED_2 = 12; // RED | |
// プッシュボタンが接続されているピン | |
const int BUTTON_1 = 8; // YELLOW | |
const int BUTTON_2 = 7; // RED | |
// 入力ピンの状態 | |
int val_1 = 0; // YELLOW | |
int val_2 = 0; // RED | |
void setup() { | |
pinMode(LED_1, OUTPUT); | |
pinMode(LED_2, OUTPUT); | |
pinMode(BUTTON_1, INPUT); | |
pinMode(BUTTON_2, INPUT); | |
} | |
void loop() { | |
val_1 = digitalRead(BUTTON_1); | |
val_2 = digitalRead(BUTTON_2); | |
if (val_1 == HIGH) { | |
digitalWrite(LED_1, HIGH); | |
delay(10); | |
} else { | |
digitalWrite(LED_1, LOW); | |
delay(10); | |
} | |
if (val_2 == HIGH) { | |
digitalWrite(LED_2, HIGH); | |
delay(10); | |
} else { | |
digitalWrite(LED_2, LOW); | |
delay(10); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment