Skip to content

Instantly share code, notes, and snippets.

@hollyhockberry
Created October 22, 2021 11:23
Show Gist options
  • Save hollyhockberry/7e320d9b428ca963d4199b1e77719c80 to your computer and use it in GitHub Desktop.
Save hollyhockberry/7e320d9b428ca963d4199b1e77719c80 to your computer and use it in GitHub Desktop.
M5 Fader unit: LED out 1
#include <Arduino.h>
#include <FastLED.h>
constexpr int pin_fader = 33;
constexpr int pin_led = 32;
constexpr int led_count = 14;
CRGB leds[led_count];
long show = 0;
void setup() {
::pinMode(pin_fader, INPUT);
FastLED.addLeds<NEOPIXEL, pin_led>(leds, led_count);
FastLED.setBrightness(64);
}
void loop() {
auto adc = ::analogRead(pin_fader);
auto n = map(adc, 0, 4095, 0, led_count);
if (show == n) {
return;
}
show = n;
int i;
for (i = 0; i < show; ++i)
leds[i] = CRGB::White;
for (; i < led_count; ++i)
leds[i] = CRGB::Black;
FastLED.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment