I was hoping to get to a car meet tomorrow and while my pi 5 and ai are being built i am adding an s3 dev kit to my front voice visual kit but i cant seem to get the code to play nice.
So it is done like this.
I have 4 x 85cm led strips horizontal on the crash bar, these have level shifters at the strips and the strips are powered by their own buck (all earths are local)
I want the s3 to do 2 things...
When my pir sensors are triggered and the voice starts, the voice uses the strips to display the voice in a fluid centre out visual like Kitt and then when the voice stops playing an idle scan kicks in for 3 min scanning from centre out.
If the pir is triggered again the s3 will cut in and allow the voice to use the led strips and then when finished it drops back to idle scan and 3 min timer starts again. If it is not triggered withing 3 min the led strips turn off and the system awaits the voice being triggered again and this whole process restarts.
I have a version that works, the voice triggers but it comes out from the left and not centre out. Then when the voice ends the idle scan kicks in and if voice is triggered it cuts back in but again from the left.
SO it is basically there it just has 2 problems
1. the voice bit needs changing to centre out.
2. When you take power off and re attach power the whole things changes and is no longer the same, something to do with the leds receiving signal before the s3 has booted or something.
I use Ai to help me code but it has me spinning in circles at min. If i ask it to fix the code it changes it completely.
Can anyone here help me sort the code so that it works?
Any help would be greatly appreciated.
This is the code...
#include <FastLED.h>
#define LED_PIN1 6 // LED Pair 1
#define LED_PIN2 7 // LED Pair 2
#define NUM_LEDS 51 // LEDs per pair
#define BRIGHTNESS 150
#define COLOR CRGB::Red
#define STROBE_PIN 8 // MSGEQ7 STROBE
#define RESET_PIN 4 // MSGEQ7 RESET
#define AUDIO_PIN 3 // MSGEQ7 OUT (ADC)
#define IDLE_TIMEOUT 180000 // 3 min in ms
CRGB leds1[NUM_LEDS];
CRGB leds2[NUM_LEDS];
unsigned long lastActivityTime = 0;
bool idleActive = false; // start idle OFF
int trailLength = 5;
int center = NUM_LEDS / 2;
int step = 0;
int direction = 1;
void setup() {
FastLED.addLeds<WS2812, LED_PIN1, GRB>(leds1, NUM_LEDS);
FastLED.addLeds<WS2812, LED_PIN2, GRB>(leds2, NUM_LEDS);
FastLED.clear();
FastLED.show();
pinMode(STROBE_PIN, OUTPUT);
pinMode(RESET_PIN, OUTPUT);
pinMode(AUDIO_PIN, INPUT);
lastActivityTime = millis();
}
void loop() {
int audioValue = analogRead(AUDIO_PIN); // 0-4095 on S3
bool triggered = audioValue > 1200; // adjust threshold for your audio
if (triggered) {
// Voice triggered mode
idleActive = false;
lastActivityTime = millis();
// Example: simple red bar proportional to audio
int level = map(audioValue, 0, 4095, 0, NUM_LEDS);
FastLED.clear();
for (int i = 0; i < level; i++) {
leds1[i] = COLOR;
leds2[i] = COLOR;
}
FastLED.show();
} else {
// Idle scan
if (!idleActive) {
idleActive = true;
lastActivityTime = millis();
step = 0;
direction = 1;
}
FastLED.clear();
// Mirrored trail
for (int i = 0; i < trailLength; i++) {
int outPos = step - i * direction;
int leftPos = center - outPos;
int rightPos = center + outPos;
if (leftPos >= 0 && leftPos < NUM_LEDS) {
leds1[leftPos] = COLOR;
leds2[leftPos] = COLOR;
}
if (rightPos >= 0 && rightPos < NUM_LEDS) {
leds1[rightPos] = COLOR;
leds2[rightPos] = COLOR;
}
if (i > 0) {
if (leftPos >= 0 && leftPos < NUM_LEDS) {
leds1[leftPos].fadeToBlackBy(i * 50);
leds2[leftPos].fadeToBlackBy(i * 50);
}
if (rightPos >= 0 && rightPos < NUM_LEDS) {
leds1[rightPos].fadeToBlackBy(i * 50);
leds2[rightPos].fadeToBlackBy(i * 50);
}
}
}
FastLED.show();
step += direction;
if (step <= 0 || step >= center) direction *= -1;
}
// Reset idle timer
if (idleActive && (millis() - lastActivityTime > IDLE_TIMEOUT)) {
FastLED.clear();
FastLED.show();
lastActivityTime = millis(); // restart idle scan
}
delay(30); // adjust speed
}