Created
October 22, 2021 11:36
-
-
Save hollyhockberry/3972effa1708f9fb491dab2842cc7494 to your computer and use it in GitHub Desktop.
M5 Fader unit: LED out 2
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
#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() { | |
constexpr int left[] = { 0, 1, 2, 3, 4, 5, 6 }; | |
constexpr int right[] = { 13, 12, 11, 10, 9, 8, 7 }; | |
auto adc = ::analogRead(pin_fader); | |
auto n = map(adc, 0, 4095, 7, 0); | |
if (show == n) { | |
return; | |
} | |
show = n; | |
int i; | |
for (i = 0; i < show; ++i) | |
leds[left[i]] = leds[right[i]] = CRGB::Black; | |
for (; i < 7; ++i) | |
leds[left[i]] = leds[right[i]] = CRGB::White; | |
FastLED.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment