Skip to content

Instantly share code, notes, and snippets.

@baobao
Created August 19, 2019 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/dcda3a8cacc0af890ba573cbbdcdf144 to your computer and use it in GitHub Desktop.
Save baobao/dcda3a8cacc0af890ba573cbbdcdf144 to your computer and use it in GitHub Desktop.
/**
* ゆっくり明るくなって、暗くなるを繰り返すサンプル
*/
int led = 9;
int brightness = 0;
int fadeAmount = 2;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
analogWrite(led, brightness);
// 明るさの量を加算
brightness += fadeAmount;
if (brightness <= 0 || brightness >= 255)
{
// 0以下、255以上になったら符号を変える
fadeAmount = fadeAmount * -1;
}
delay(15);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment