Created
December 21, 2019 06:35
-
-
Save likersacademia/15666206738dd662f698fa4187e6b53d to your computer and use it in GitHub Desktop.
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 red_LED = 5; // 赤LEDが接続されているピン | |
const int blue_LED = 10; // 青LEDが接続されているピン | |
const int green_LED = 15; // 緑LEDが接続されているピン | |
const int PRESS = A5; // センサーが接続されているピン | |
int val = 0; // 入力ピンの状態がこの変数(val)に記憶される | |
int state = 0; // LEDの状態(0ならオフ、1ならオン) | |
void setup() { | |
pinMode(red_LED, OUTPUT); | |
pinMode(blue_LED, OUTPUT); | |
pinMode(green_LED, OUTPUT); | |
pinMode(PRESS, INPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
float press = analogRead(PRESS); | |
Serial.print(val); | |
Serial.println("強さ "); | |
val = analogRead(PRESS); // 入力を読み取りvalに格納 | |
//変化があるかどうかチェック | |
if ((val > 50)) { | |
state = (state + 1) % 4; | |
delay(100); | |
} | |
if (state == 0) { | |
digitalWrite(red_LED, HIGH); | |
digitalWrite(blue_LED, HIGH); | |
digitalWrite(green_LED, HIGH); | |
} else if (state == 1) { | |
digitalWrite(red_LED, LOW); | |
digitalWrite(blue_LED, HIGH); | |
digitalWrite(green_LED, HIGH); | |
} else if (state == 2) { | |
digitalWrite(red_LED, HIGH); | |
digitalWrite(blue_LED, LOW); | |
digitalWrite(green_LED, HIGH); | |
} else if (state == 3) { | |
digitalWrite(red_LED, HIGH); | |
digitalWrite(blue_LED, HIGH); | |
digitalWrite(green_LED, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment