Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ポテンショメータを使って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