ui and edge leds working with pwmaudio and sdio

This commit is contained in:
Sebastian
2025-05-28 00:43:05 +02:00
parent c9b6220449
commit 499d5f2c63

View File

@ -3,7 +3,8 @@
#include <TCA9555.h>
#include <AS5600.h>
#include <Adafruit_NeoPixel.h>
//#include <Adafruit_NeoPixel.h>
#include <FastLED.h>
#include <PWMAudio.h>
#include <I2S.h>
#include <SPI.h>
@ -22,8 +23,12 @@ PWMAudio ui_snd(8);
enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
Adafruit_NeoPixel ui_pixels(74, 5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel edge_pixels(11, 4, NEO_GRB + NEO_KHZ800);
CRGB ui_leds[74];
CRGB edge_leds[11];
//Adafruit_NeoPixel ui_pixels(74, 5, NEO_GRB + NEO_KHZ800);
//Adafruit_NeoPixel edge_pixels(11, 4, NEO_GRB + NEO_KHZ800);
volatile bool flag = false;
volatile bool click = false;
@ -87,6 +92,9 @@ void setup() {
Serial.begin();
delay(2000);
FastLED.addLeds<NEOPIXEL, 4>(edge_leds, 11);
FastLED.addLeds<NEOPIXEL, 5>(ui_leds, 74);
pinMode(21, INPUT_PULLUP);
sd_card_detected = !digitalRead(21);
delay(500);
@ -152,10 +160,6 @@ void setup() {
digitalWrite(7, LOW);
edge_pixels.begin();
delay(100);
ui_pixels.begin();
digitalWrite(6, HIGH);
delay(50);
digitalWrite(6, LOW);
@ -184,23 +188,23 @@ uint32_t lastTime = 0;
int32_t position = 0;
void loop() {
ui_pixels.clear(); // Set all pixel colors to 'off'
edge_pixels.clear(); // Set all pixel colors to 'off'
//ui_pixels.clear(); // Set all pixel colors to 'off'
//edge_pixels.clear(); // Set all pixel colors to 'off'
position = ENC.getCumulativePosition();
sd_card_detected = !digitalRead(21);
if(sd_card_detected) edge_pixels.setPixelColor(8, edge_pixels.Color(0,25,0));
if(!sd_card_detected) edge_pixels.setPixelColor(8, edge_pixels.Color(25,0,0));
if(sd_card_detected) edge_leds[8] = CRGB(0,25,0);
if(!sd_card_detected) edge_leds[8] = CRGB(25,0,0);
// EDGE LEDs
for (int i = 0; i < 8; i++) {
edge_pixels.setPixelColor(i, edge_pixels.Color(config.edge_color_r, config.edge_color_g, config.edge_color_b));
edge_leds[i] = CRGB(config.edge_color_r, config.edge_color_g, config.edge_color_b);
}
// LED Ring leeren
for (int i = 0; i < 48; i++) {
ui_pixels.setPixelColor(i + 3, ui_pixels.Color(0, 0, 0));
ui_leds[i + 3] = CRGB(0, 0, 0);
}
// flag = true when a button is pushed
@ -226,7 +230,7 @@ void loop() {
// Flash led ring
for (int i = 0; i < 48; i++) {
ui_pixels.setPixelColor(i + 3, ui_pixels.Color(0, 15, 0));
ui_leds[i + 3] = CRGB(0, 15, 0);
}
// Switch through LED matrix
@ -239,26 +243,25 @@ void loop() {
}
// Rotary button LEDs
ui_pixels.setPixelColor(0, ui_pixels.Color(0, 0, 15));
ui_pixels.setPixelColor(1, ui_pixels.Color(0, 0, 15));
ui_pixels.setPixelColor(2, ui_pixels.Color(0, 0, 15));
ui_leds[0] = CRGB(0, 0, 15);
ui_leds[1] = CRGB(0, 0, 15);
ui_leds[2] = CRGB(0, 0, 15);
// empty LED matrix
for (int i = 0; i < 13; i++) {
ui_pixels.setPixelColor(i + 3 + 48 + 4, ui_pixels.Color(0, 0, 0));
ui_leds[i + 3 + 48 + 4] = CRGB(0, 0, 0);
}
// set active LED matrix LED
ui_pixels.setPixelColor(active + 3 + 48 + 4, ui_pixels.Color(255, 255, 255));
ui_leds[active + 3 + 48 + 4] = CRGB(255, 255, 255);
if(position < 0) position += 4096;
active_led_ring = (position / 32) % 48;
// set active LED ring LED
ui_pixels.setPixelColor(active_led_ring + 3, ui_pixels.Color(255, 255, 255));
ui_leds[active_led_ring + 3] = CRGB(255, 255, 255);
ui_pixels.show();
edge_pixels.show();
FastLED.show();
delay(1); // wait 1ms
}