what i want to do is to use an SD-Card+Reader with Glediator Recordings on the Card in combination with the Adafruit NeoPixel library to control 100 WS2811/12 LEDs .
Actually it is working with the FastLED library but to rewrite the whole code would take a very long time, so can anybody help me how i can do it with NeoPixel?
This is the actual Test-Code:
#include <FastLED.h>
#include <SPI.h>
#include <SD.h>
#define NUM_LEDS 16 // LED number
#define DATA_PIN 7 // your data arduino pin
#define CHIPSET WS2811 // your LED chip type
#define CMD_NEW_DATA 1
//#define BAUD_RATE 500000 //if using Glediator via serial
unsigned char x = 16; // matrix x size
unsigned char y = 1; // matrix y size
File fxdata;
CRGB leds[NUM_LEDS];
void setup()
{
FastLED.addLeds<CHIPSET, DATA_PIN, GRB>(leds, NUM_LEDS); //see doc for different LED strips
pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work.
digitalWrite(10, HIGH); // workaround for sdcard failed error...
SD.begin(10); //anstatt zwei zeilen drunter in if schleife...
}
int serialGlediator ()
{
while (!Serial.available()) {}
return Serial.read();
}
void loop()
{
fxdata = SD.open("myanim.dat"); // read only
while (fxdata.available())
{
fxdata.readBytes((char*)leds, NUM_LEDS*3);
// ledSort(1); //1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right)
FastLED.show();
delay(50); // set the speed of the animation. 20 is appx ~ 500k bauds
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
}
The only thing i dont know what it's really doing and how it would be done with Adafruit NeoPixel is this line: CRGB leds[NUM_LEDS];
Because i already wrote a really large code including the NeoPixel library and to do the research what all this would be if it was coded with the fastLED library would take much much longer than to do it this way…
Do you know what it exactly does? And how i could rewrite the test-code?
Leon2212:
The only thing i dont know what it's really doing and how it would be done with Adafruit NeoPixel is this line: CRGB leds[NUM_LEDS];
That's instantiating an array (size 'NUM_LEDS') of objects of the CRGB class. With the NeoPixel library, space to hold the LED information is allocated internal to the object. The number of LEDs in the strip is passed through the constructor when a 'Adafruit_NeoPixel' object is created.
Leon2212:
So can i use the CRGB class also in the NeoPixel library?
No, the CRGB class is defined by the FastLED library.
And how do i have to rewrite this part of the test code for NeoPixel library to do the same thing??
fxdata.readBytes((char*)leds, NUM_LEDS*3);
You could read the file into a RAM buffer and use that to set the pixels' colors using the methods of the Adafruit_NeoPixel object. But, that would double your RAM usage. So, you could also iterate through the file three bytes at a time to read the color information and then set the corresponding pixel in the Adafruit_NeoPixel object.
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#include <SD.h>
#define PIN 7
#define NUM_LEDS 100
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
#define CMD_NEW_DATA 1
File fxdata;
//CRGB leds[NUM_LEDS]; -> old with fastLED
char leds[NUM_LEDS*3]; // "new" with NeoPixel ??
int counter;
void setup()
{
pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work.
digitalWrite(10, HIGH); // workaround for sdcard failed error...
SD.begin(10);
}
int serialGlediator ()
{
while (!Serial.available()) {}
return Serial.read();
}
void loop()
{
fxdata = SD.open("myanim.dat"); // read only
while (fxdata.available())
{
fxdata.readBytes((char*)leds, NUM_LEDS*3);
for (counter = 0; counter < 300; counter +3)
{
pixels.setPixelColor(counter/3, pixels.Color(leds[counter],leds[counter+1],leds[counter+2]));
}
pixels.show();
delay(50); // set the speed of the animation. 20 is appx ~ 500k bauds
}
// close the file in order to prevent hanging IO or similar throughout time
fxdata.close();
}
I don't know why you keep insisting on wanting to replicate the CRGB array. As I said in my first reply, the NeoPixel library allocates the required space internally. Also, what makes your think the FILE class has a 'setPixelColor()' method? That can't possible even compile!
Looking at your original Test-Code again, I'm thinking an easier way would be to just access this internal storage directly. Look at the source code for the 'getPixel()' method in Adafruit_NeoPixel.h and Adafruit_NeoPixel.cpp. Make sure you understand it. It will return a pointer to that internal storage. You can probably use that pointer in the call to 'fxdata.readBytes()'. The usual care when working with pointers is required. Be sure to know where you're writing.
Finally, when posting code, please use Code Tags so it looks like this:
void setup()
{
FastLED.addLeds<CHIPSET, DATA_PIN, GRB>(leds, NUM_LEDS); //see doc for different LED strips
pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work.
digitalWrite(10, HIGH); // workaround for sdcard failed error...
SD.begin(10); //anstatt zwei zeilen drunter in if schleife...
}
int serialGlediator ()
{
while (!Serial.available()) {}
return Serial.read();
}
I'm not sure what you are using, but it's not as easy to read.
Sorry for posting the code wrong… Hope it's better now!
I don't necessarily need to replicate the CRGB array, i only need to understand it and i'm searching for a solution to do it in an other way with neopixel..
I really don't know much about FastLED and i don't know where to start:
If you can give me some helpful advise i would love to work on the rest on my own!
How would tha work exactly with a pointer? How would that look like?
Can i access directly the information on the sd card?
And another problem is how do i let the code read the information on the sd card and convert it in something else which pixels.setPixelColor can understand?
Looking at your original Test-Code again, I'm thinking an easier way would be to just access this internal storage directly. Look at the source code for the 'getPixel()' method in Adafruit_NeoPixel.h and Adafruit_NeoPixel.cpp. Make sure you understand it. It will return a pointer to that internal storage. You can probably use that pointer in the call to 'fxdata.readBytes()'. The usual care when working with pointers is required. Be sure to know where you're writing.
Is it this what you said / what i am looking for?
// Returns pointer to pixels[] array. Pixel data is stored in device-
// native format and is not translated here. Application will need to be
// aware of specific pixel data format and handle colors appropriately.
uint8_t *Adafruit_NeoPixel::getPixels(void) const {
return pixels;
}/code]
So, .. I hope i got this right, please gfvalvo check it also.
I had done something similar reading dmxValues straight into the led buffer (with an RGB toggle added to it) and i combine that with what you guys had written here already. So if this is the object declarationAdafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
then reading a value into the pixelpointer (the function i added to the library comes down to the same thing)uint8_t * pixelpointer=pixels.getPixels(); and then reading the file straight into the Array's Object :