Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active December 7, 2018 02:37
Show Gist options
  • Save baobao/d6fbd47960c7472a52dae51cf95913bc to your computer and use it in GitHub Desktop.
Save baobao/d6fbd47960c7472a52dae51cf95913bc to your computer and use it in GitHub Desktop.
光センサー使用サンプル
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop()
{
int val = analogRead(0);
// 取得した明るさの強さをログに吐く
Serial.println(val);
// 100*5/1023 = 約0.488V未満だったらLEDを点灯させる
if (val < 100)
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment