bigjosh / SimpleNeoPixelDemo

A demonstration showing how easy it can be to drive WS2812 NeoPixels
MIT License
223 stars 59 forks source link

Demo Request #18

Open jammerxd opened 3 years ago

jammerxd commented 3 years ago

Hi Josh,

I'd like to thank you for this awesome demo script. I just have a request/question on how to use this effectively. I wish to receive a spectrum dump over the serial line every 8 to 33ms that contains 7 "bins" of spectrum data(integers ranging from 0 to 100). Based on that data I want to generate a waveform/wave effect that "ripples" through the strip. I know this is vague and generic but I'm wondering how to accomplish this as previous methods involved storing a "buffer" of all the values then shifting each value 1 by 1 but that doesn't seem to be valid with your program. I tried using a buffer to accomplish this but it just made the LEDs randomly flash instead of moving pixel 1 to pixel 2 and pixel 2 to pixel 3 and pixel 3 to pixel 4 etc... I've attached a sample of what I'm trying to do.

My Attempt

mmmdwyer commented 2 years ago

My solution to this was to hold the paintbrush still and move the canvas, which this library uniquely enables you to do with memory efficiency.

Here's my 1-bit hack:

char bitmap[NUMPIXELS];  
int pos = 0;
void loop() {
  cli();
  for (int i = 0; i < NUMPIXELS; i++) {
     sendPixel( 0 , 0 , bitmap[((pos + i) % NUMPIXELS)]);
     // Start at the current pos, add in the offset, and use the modulo to wrap around
     }
  delay(FRAMEDELAY); // This is also our SHOW
  pos = ((pos + 1) % NUMPIXELS); // This moves the canvas one slot over
  sei();
}