Skip to content

Instantly share code, notes, and snippets.

@natcl
Created February 12, 2021 01:39
Show Gist options
  • Save natcl/4446407850fa5f41744728df8319ff72 to your computer and use it in GitHub Desktop.
Save natcl/4446407850fa5f41744728df8319ff72 to your computer and use it in GitHub Desktop.
ledPot
#include <Adafruit_NeoPixel.h>
#include <Bounce2.h>
#define LED_PIN 17
#define BUTTON_PIN 3
#define POT_PIN 14
#define NUM_LEDS 83
#define BRIGHTNESS 100
byte lastValue = 0;
byte mode = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
Bounce debouncer = Bounce();
uint32_t colors[] = {
strip.Color(255, 0, 0),
strip.Color(0, 255, 0),
strip.Color(0, 0, 255),
strip.Color(255, 0, 255),
strip.Color(255, 255, 0),
strip.Color(0, 255, 255),
strip.Color(255, 255, 255),
strip.Color(random(0,255), random(0,255), random(0,255))
};
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
debouncer.attach(BUTTON_PIN);
debouncer.interval(20);
Serial.begin(115200);
strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
debouncer.update();
byte potValue = map(analogRead(POT_PIN), 0, 1023, 0, 83);
if (debouncer.fell()) {
colors[sizeof(colors)/4-1] = strip.Color(random(0,255), random(0,255), random(0,255));
mode++;
if (mode == sizeof(colors)/4) {
mode = 0;
}
Serial.println(mode);
}
if (potValue != lastValue) {
Serial.println(potValue);
strip.clear();
for (byte i=0; i < potValue; i++) {
strip.setPixelColor(i, colors[mode]);
}
strip.show();
}
lastValue = potValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment