Created
April 17, 2024 06:05
-
-
Save uchan-nos/37b6d3d9361bddaea38a57af3a3a0411 to your computer and use it in GitHub Desktop.
可変抵抗器でLEDの点滅パターンを選択するArduinoスケッチ
This file contains hidden or 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
// for Raspberry Pi Pico | |
void setup() { | |
} | |
int tick = 0; | |
const unsigned char pattern3[8] = {255, 0, 255, 0, 255, 127, 63, 31}; | |
void loop() { | |
int v = analogRead(A0); | |
int sel = v * 3 / 1024; // sel: 0 ~ 2 | |
switch (sel) { | |
case 0: | |
if (tick < 500) { | |
analogWrite(25, tick / 2); | |
} else { | |
analogWrite(25, 250 - (tick - 500) / 2); | |
} | |
break; | |
case 1: | |
analogWrite(25, (tick < 500) * 255); | |
break; | |
case 2: | |
analogWrite(25, pattern3[tick / 125]); | |
break; | |
} | |
tick = (tick + 1) % 1000; | |
delay(2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment