DJ Namaste
Active member
Hello
I found a way to perform POV - Persistence Of Vision images using the Adafruit Neopixel library with a bit of code I modified. The code runs on Teensy lc but on teensy 2.0 the dynamic memory is something like 95% and it will not run the code. The teensy will run FastLED POV code fine but I have put a lot of time into the NeoPixel Library. Im hoping to get a few images along with rainbow fades and stuff. My question is can I clean up the code so that it is able to run on slower processors like teensy 2.0?
I know it can be done in an easier way but any help would be appreciated.
Here is the code. There is only blue values entered to keep the file size lower. The code below works okay on teensy lc but not on teensy 2.0.
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#define PIN 17
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(32, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
PovX(0);
}
void PovX(uint8_t wait) {
int blue[32][32] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 255, 255, 255, 255, 192, 192, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 255, 255, 255, 255, 255, 255, 255, 255, 192, 192, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 192, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 192, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 192, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 128, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 128, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 192, 255, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 192, 0, 0, 0, 0, 0, 0,
0, 0, 128, 192, 0, 0, 0, 192, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 192, 0, 0, 0, 192, 128, 0, 0,
0, 0, 255, 255, 192, 0, 0, 128, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 0, 0, 192, 255, 255, 0, 0,
0, 0, 192, 255, 128, 0, 0, 192, 255, 192, 0, 0, 0, 255, 255, 255, 255, 255, 255, 0, 0, 0, 192, 255, 192, 0, 0, 128, 255, 192, 0, 0,
0, 255, 128, 255, 255, 128, 0, 255, 255, 0, 0, 0, 0, 0, 192, 255, 255, 192, 0, 0, 0, 0, 0, 255, 255, 0, 128, 255, 255, 128, 255, 0,
0, 255, 255, 255, 255, 255, 0, 255, 255, 128, 0, 0, 0, 255, 255, 192, 192, 255, 255, 0, 0, 0, 128, 255, 255, 0, 255, 255, 255, 255, 255, 0,
0, 0, 0, 0, 128, 255, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 255, 128, 0, 0, 0, 0,
0, 0, 0, 0, 0, 128, 0, 128, 255, 255, 255, 255, 255, 255, 192, 0, 0, 192, 255, 255, 255, 255, 255, 255, 128, 0, 128, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 255, 255, 192, 0, 0, 0, 0, 192, 255, 255, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 255, 255, 128, 255, 255, 128, 255, 255, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 192, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 192, 255, 255, 255, 255, 255, 255, 192, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 255, 255, 192, 255, 255, 255, 255, 255, 255, 192, 255, 255, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 128, 255, 0, 0, 192, 255, 255, 255, 192, 255, 255, 192, 255, 255, 255, 192, 0, 0, 255, 128, 0, 0, 0, 0, 0, 0,
0, 128, 255, 255, 0, 255, 255, 255, 255, 0, 0, 255, 255, 255, 192, 192, 192, 192, 255, 255, 255, 0, 0, 255, 255, 255, 255, 0, 255, 255, 128, 0,
0, 192, 255, 255, 255, 255, 255, 192, 0, 0, 0, 0, 128, 255, 255, 255, 255, 255, 255, 128, 0, 0, 0, 0, 192, 255, 255, 255, 255, 255, 192, 0,
0, 0, 0, 128, 192, 255, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 255, 192, 128, 0, 0, 0,
0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0,
0, 0, 0, 128, 255, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 255, 128, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
int green[32][32] =
{
};
int red[32][32] =
{
// { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
// { 0,220, 0, 0, 0, 0, 0, 0,220, 0},
// { 0, 0,220, 0, 0, 0, 0,220, 0, 0},
// { 0, 0, 0,220, 0, 0,220, 0, 0, 0},
// { 0, 0, 0, 0,250,220, 0, 0, 0, 0},
// { 0, 0, 0, 0,220,220, 0, 0, 0, 0},
// { 0, 0, 0,220, 0, 0,220, 0, 0, 0},
// { 0, 0,220, 0, 0, 0, 0,220, 0, 0},
// { 0,220, 0, 0, 0, 0, 0, 0,220, 0},
// { 220, 0, 0, 0, 0, 0, 0, 0, 0,220},
};
for(int row=0; row<32; row++){
for(int col=0; col<32; col++){
int index = col+1;
uint32_t c = strip.Color(red[row][col], green[row][col], blue[row][col]);
strip.setPixelColor(index, c);
strip.setPixelColor(index+1, c);
strip.setPixelColor(index+2, c);
}
strip.show();
for(int i=0; i<strip.numPixels(); i++){
strip.setPixelColor(i,0);
}
int wait = 2;
delay(wait);
}
}
I found a way to perform POV - Persistence Of Vision images using the Adafruit Neopixel library with a bit of code I modified. The code runs on Teensy lc but on teensy 2.0 the dynamic memory is something like 95% and it will not run the code. The teensy will run FastLED POV code fine but I have put a lot of time into the NeoPixel Library. Im hoping to get a few images along with rainbow fades and stuff. My question is can I clean up the code so that it is able to run on slower processors like teensy 2.0?
I know it can be done in an easier way but any help would be appreciated.
Here is the code. There is only blue values entered to keep the file size lower. The code below works okay on teensy lc but not on teensy 2.0.
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#define PIN 17
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(32, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
PovX(0);
}
void PovX(uint8_t wait) {
int blue[32][32] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 255, 255, 255, 255, 192, 192, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 255, 255, 255, 255, 255, 255, 255, 255, 192, 192, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 192, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 192, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 192, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 128, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 128, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 192, 255, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 192, 0, 0, 0, 0, 0, 0,
0, 0, 128, 192, 0, 0, 0, 192, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 192, 0, 0, 0, 192, 128, 0, 0,
0, 0, 255, 255, 192, 0, 0, 128, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 0, 0, 192, 255, 255, 0, 0,
0, 0, 192, 255, 128, 0, 0, 192, 255, 192, 0, 0, 0, 255, 255, 255, 255, 255, 255, 0, 0, 0, 192, 255, 192, 0, 0, 128, 255, 192, 0, 0,
0, 255, 128, 255, 255, 128, 0, 255, 255, 0, 0, 0, 0, 0, 192, 255, 255, 192, 0, 0, 0, 0, 0, 255, 255, 0, 128, 255, 255, 128, 255, 0,
0, 255, 255, 255, 255, 255, 0, 255, 255, 128, 0, 0, 0, 255, 255, 192, 192, 255, 255, 0, 0, 0, 128, 255, 255, 0, 255, 255, 255, 255, 255, 0,
0, 0, 0, 0, 128, 255, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 255, 128, 0, 0, 0, 0,
0, 0, 0, 0, 0, 128, 0, 128, 255, 255, 255, 255, 255, 255, 192, 0, 0, 192, 255, 255, 255, 255, 255, 255, 128, 0, 128, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 255, 255, 192, 0, 0, 0, 0, 192, 255, 255, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 255, 255, 128, 255, 255, 128, 255, 255, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 192, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 192, 255, 255, 255, 255, 255, 255, 192, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 255, 255, 192, 255, 255, 255, 255, 255, 255, 192, 255, 255, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 128, 255, 0, 0, 192, 255, 255, 255, 192, 255, 255, 192, 255, 255, 255, 192, 0, 0, 255, 128, 0, 0, 0, 0, 0, 0,
0, 128, 255, 255, 0, 255, 255, 255, 255, 0, 0, 255, 255, 255, 192, 192, 192, 192, 255, 255, 255, 0, 0, 255, 255, 255, 255, 0, 255, 255, 128, 0,
0, 192, 255, 255, 255, 255, 255, 192, 0, 0, 0, 0, 128, 255, 255, 255, 255, 255, 255, 128, 0, 0, 0, 0, 192, 255, 255, 255, 255, 255, 192, 0,
0, 0, 0, 128, 192, 255, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 255, 192, 128, 0, 0, 0,
0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0,
0, 0, 0, 128, 255, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 255, 128, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
int green[32][32] =
{
};
int red[32][32] =
{
// { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
// { 0,220, 0, 0, 0, 0, 0, 0,220, 0},
// { 0, 0,220, 0, 0, 0, 0,220, 0, 0},
// { 0, 0, 0,220, 0, 0,220, 0, 0, 0},
// { 0, 0, 0, 0,250,220, 0, 0, 0, 0},
// { 0, 0, 0, 0,220,220, 0, 0, 0, 0},
// { 0, 0, 0,220, 0, 0,220, 0, 0, 0},
// { 0, 0,220, 0, 0, 0, 0,220, 0, 0},
// { 0,220, 0, 0, 0, 0, 0, 0,220, 0},
// { 220, 0, 0, 0, 0, 0, 0, 0, 0,220},
};
for(int row=0; row<32; row++){
for(int col=0; col<32; col++){
int index = col+1;
uint32_t c = strip.Color(red[row][col], green[row][col], blue[row][col]);
strip.setPixelColor(index, c);
strip.setPixelColor(index+1, c);
strip.setPixelColor(index+2, c);
}
strip.show();
for(int i=0; i<strip.numPixels(); i++){
strip.setPixelColor(i,0);
}
int wait = 2;
delay(wait);
}
}