Created
August 19, 2019 14:39
-
-
Save baobao/dcda3a8cacc0af890ba573cbbdcdf144 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
/** | |
* ゆっくり明るくなって、暗くなるを繰り返すサンプル | |
*/ | |
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