Skip to content

Instantly share code, notes, and snippets.

@uchan-nos
Created April 17, 2024 06:05
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 uchan-nos/37b6d3d9361bddaea38a57af3a3a0411 to your computer and use it in GitHub Desktop.
Save uchan-nos/37b6d3d9361bddaea38a57af3a3a0411 to your computer and use it in GitHub Desktop.
可変抵抗器でLEDの点滅パターンを選択するArduinoスケッチ
// 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