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を点滅スピードを変更するサンプル | |
int sensorPin = A0; | |
int ledPin = 13; | |
int sensorValue = 0; | |
void setup() | |
{ | |
pinMode(ledPin, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
// 0~5Vの電圧を0~1023の値に変換する | |
sensorValue = analogRead(sensorPin); | |
Serial.println(sensorValue); | |
// 下限を適当に指定しておく | |
if (sensorValue < 50){ | |
sensorValue = 50; | |
} | |
// 電圧値が低いほど点滅速度が速くなる | |
digitalWrite(ledPin, HIGH); | |
delay(sensorValue); | |
digitalWrite(ledPin, LOW); | |
delay(sensorValue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment