#include <Arduino.h>
// #include <I2S.h>
#include "FastLED.h"
#define FRONT_LED_PIN 26
#define BACK_LED_PIN 27
#define BASS_LED_PIN 4
#define NUM_LEDS 64
#define HEIGHT 8
#define WIDTH 8
#define NUM_EXTRA_LEDS 2
#define INPUT_DETECTION_PIN 28
#define LRCK_PIN 29
#define BCK_PIN 3
#define SCK_PIN 2
#define DIN_PIN 0
#define DOUT_PIN 1
#define ROTARY_A_PIN 6
#define ROTARY_B_PIN 7
CRGB front_leds[NUM_LEDS];
CRGB back_leds[NUM_LEDS];
CRGB bass_leds[NUM_EXTRA_LEDS];
int brightness = 255;
void setup()
{
Serial.begin(9600);
FastLED.addLeds<WS2812B, FRONT_LED_PIN, GRB>(front_leds, NUM_LEDS);
FastLED.addLeds<WS2812B, BACK_LED_PIN, GRB>(back_leds, NUM_LEDS);
FastLED.addLeds<WS2812B, NUM_EXTRA_LEDS, GRB>(bass_leds, NUM_LEDS);
FastLED.setBrightness(brightness);
pinMode(INPUT_DETECTION_PIN, INPUT_PULLUP);
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < random(HEIGHT); y++) {
front_leds[getPixelIndex(x, y)] = getColorByX(x);
}
}
FastLED.show();
}
bool inputDetect = false;
void detectInput() {
bool currentInputDetect = digitalRead(INPUT_DETECTION_PIN);
if (currentInputDetect != inputDetect) {
if (currentInputDetect) {
Serial.println("Jack plugged in");
}
else {
Serial.println("Jack unplugged");
}
inputDetect = currentInputDetect;
}
}
int getPixelIndex(int x, int y) {
return x * HEIGHT + y;
}
CHSV getColorByX(int x) {
int hue = 255 * x / WIDTH;
return CHSV(hue, 255, 255);
}
void simulate() {
static int lastUpdate = 0;
if (lastUpdate + 750 > millis()) return;
for (int i = 0; i < NUM_LEDS; i++) {
front_leds[i] = CRGB::Black;
}
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < random(HEIGHT); y++) {
front_leds[getPixelIndex(x, y)] = getColorByX(x);
}
}
FastLED.show();
lastUpdate = millis();
}
void loop()
{
// getButtonState();
// rainbowLeds();
// cycleLeds();
detectInput();
simulate();
delay(50);
}