I have a Shifty VU audio shield and have written a script that monitors audio input, and when the volume nearly maxes out creates an ‘interactive’ chasing stream of lights that run to the end of the display using memmove. They also jump +20 hue every time the audio maxes out. This works fine and looks cool, and if you tweak the incoming volume it picks up the beat really well. Here’s the code:
#include <FastLED.h>
#define NUM_LEDS 150
#define DATA_PIN 13
int analogPinA = 2;
int valA = 0;
int vol;
int col =0;
CRGBArray<NUM_LEDS>leds;
void setup()
{
Serial.begin(9600); // setup serial
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
analogReference(INTERNAL);
}
void loop() {
valA = analogRead(analogPinA); // read the input pin
vol = map(valA, 0, 1023, 0, 255);
if (vol < 253) vol = 0;
if (vol > 253) col = col + 20;
leds[0] = CHSV (col,255,vol);
memmove( &leds[1], &leds[0], (NUM_LEDS-1)*sizeof(CRGB));
FastLED.show();
}
But I found that with 150 leds each pulse of light takes a little while to traverse the strip, so to make it more on-the-beat I’m trying to rewrite it so that two duplicate streams of chasing light emanate out from the centre of the strip to the left and right . One would be the mirror image of the other.
But I can’t make it work. It is easy enough to modify the original stream to start at 75 through to 150. Yet I was hoping memmove would count backwards somehow, but whatever I try it won’t do that. The best I can do is to have two chasers, one from 75 - 150 and the other an exact replica from 0 -75:
void loop() {
valA = analogRead(analogPinA); // read the input pin
vol = map(valA, 0, 1023, 0, 255);
if (vol < 253) vol = 0;
if (vol > 253) col = col + 20;
leds[75] = CHSV (col,255,vol);
//CRGB last_led = leds[NUM_LEDS-1];
memmove( &leds[76], &leds[75], (NUM_LEDS)*sizeof(CRGB));
memmove( &leds[0], &leds[75], (75)*sizeof(CRGB));
FastLED.show();
}
I was hoping memmove would take a negative value and count backwards, something like this:
memmove( &leds[74], &leds[75], (-75)*sizeof(CRGB));
…but that does nothing at all.
Am I missing a trick? Is there a simple way of creating a reverse image of the activity on leds 75 - 150 on 74 > 0 ?
Thanks!