DJ Namaste
Active member
I modified it identifying a few mistakes. Now it works and displays images but they are all red.
http://pastebin.com/HEEK0q1c
http://pastebin.com/HEEK0q1c
odeston said:The form of the picture is right, (I see a hart), but colours are totaly wrong! I see BLACK instead of RED and BLUE instead of WHITE. Color codes in the array are right (0xffffff for white, for red 0xff0000).
Maybe Atmega328 is too slow? but colors are wrong even for 4X4 image =)
Please, help me.
It is more that I've worked many different systems, and have had to port code between the systems (or setup the compiler to allow users to do the porting) that I've become sensitive to these issues.It might be that the variable is declared as 'int' in 'const unsigned int array1[]' and should really be uint32_t instead. For nano, i think that int is 16bit data type. try replacing the segment above with 'const unsigned uint32_t array1[]' ??
MichaelMeissner has often reminded me to do the right thing about declaring data types, but I don't listen...
That was my 666th post on the forum... had to quickly post another....It might be that the variable is declared as 'int' in 'const unsigned int array1[]' and should really be uint32_t instead. For nano, i think that int is 16bit data type. try replacing the segment above with 'const unsigned uint32_t array1[]' ??
MichaelMeissner has often reminded me to do the right thing about declaring data types, but I don't listen...
#include <SPI.h>
#include "SerialFlash.h"
const int FlashChipSelect = 10;
//1. kwiatek 1
const unsigned int array1[] = { 0x000000, 0x000000, 0x000000, x000000, 0x000000, ...}; //end of array
const char filename1[]= "p11.bin";
//2. polish 1
const unsigned int array2[] = { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,... }; //end of array
const char filename2[]= "p12.bin";
//3. polish 2
const unsigned int array3[] = { 0x030102, 0x020204, 0x020403, 0x000200, 0x020204, ...}; //end of array
const char filename3[]= "p13.bin";
//4. polish 3
const unsigned int array4[] = { 0x000000, 0x000000, 0x000000, 0x000000, 0x0b0b0b,... }; //end of array
const char filename4[]= "p14.bin";
//5. indian 1
const unsigned int array5[] = { 0x191f41, 0x141529, 0x100d16, 0x2a2b0c, 0x51530a,... }; //end of array
const char filename5[]= "p15.bin";
void setup() {
Serial.begin(9600);
SerialFlash.begin(FlashChipSelect);
unsigned long startMillis = millis();
while (!Serial && (millis() - startMillis < 10000)) ;
delay(100);
Serial.println("START");
//TWORZENIE I ZAPISYWANIE
//////////////////////////////
SerialFlashFile file1;
Serial.println(sizeof(array1));
if (SerialFlash.exists(filename1))
{
Serial.println("Plik juz istnieje!!!");
Serial.println(filename1);
Serial.println("----------------------");
}
else{
//twórz
SerialFlash.create(filename1, sizeof(array1));
//otwórz i zapisz
file1 = SerialFlash.open(filename1);
if (file1) {
file1.write(array1, sizeof(array1));
Serial.println("----zapisalo plik-----");
Serial.println(filename1);
Serial.println("rozmiar pliku");
Serial.println(sizeof(array1));
Serial.println("----------OK-----------");
}
file1.close();
Serial.println(sizeof(array1));
}
//////////////////////////////////////
//////////////////////////////
SerialFlashFile file2;
Serial.println(sizeof(array2));
if (SerialFlash.exists(filename2))
{
Serial.println("Plik juz istnieje!!!");
Serial.println(filename2);
Serial.println("----------------------");
}
else{
//twórz
SerialFlash.create(filename2, sizeof(array2));
//otwórz i zapisz
file2 = SerialFlash.open(filename2);
if (file2) {
file2.write(array2, sizeof(array2));
Serial.println("----zapisalo plik-----");
Serial.println(filename2);
Serial.println("rozmiar pliku");
Serial.println(sizeof(array2));
Serial.println("----------OK-----------");
}
file2.close();
Serial.println(sizeof(array2));
}
//////////////////////////////////////
//////////////////////////////
SerialFlashFile file3;
Serial.println(sizeof(array3));
if (SerialFlash.exists(filename3))
{
Serial.println("Plik juz istnieje!!!");
Serial.println(filename3);
Serial.println("----------------------");
}
else{
//twórz
SerialFlash.create(filename3, sizeof(array3));
//otwórz i zapisz
file3 = SerialFlash.open(filename3);
if (file3) {
file3.write(array3, sizeof(array3));
Serial.println("----zapisalo plik-----");
Serial.println(filename3);
Serial.println("rozmiar pliku");
Serial.println(sizeof(array3));
Serial.println("----------OK-----------");
}
file3.close();
Serial.println(sizeof(array3));
}
//////////////////////////////////////
//////////////////////////////
SerialFlashFile file4;
Serial.println(sizeof(array4));
if (SerialFlash.exists(filename4))
{
Serial.println("Plik juz istnieje!!!");
Serial.println(filename4);
Serial.println("----------------------");
}
else{
//twórz
SerialFlash.create(filename4, sizeof(array4));
//otwórz i zapisz
file4 = SerialFlash.open(filename4);
if (file4) {
file4.write(array4, sizeof(array4));
Serial.println("----zapisalo plik-----");
Serial.println(filename4);
Serial.println("rozmiar pliku");
Serial.println(sizeof(array4));
Serial.println("----------OK-----------");
}
file4.close();
Serial.println(sizeof(array4));
}
//////////////////////////////////////
//////////////////////////////
SerialFlashFile file5;
Serial.println(sizeof(array5));
if (SerialFlash.exists(filename5))
{
Serial.println("Plik juz istnieje!!!");
Serial.println(filename5);
Serial.println("----------------------");
}
else{
//twórz
SerialFlash.create(filename5, sizeof(array5));
//otwórz i zapisz
file5 = SerialFlash.open(filename5);
if (file5) {
file5.write(array5, sizeof(array5));
Serial.println("----zapisalo plik-----");
Serial.println(filename5);
Serial.println("rozmiar pliku");
Serial.println(sizeof(array5));
Serial.println("----------OK-----------");
}
file5.close();
Serial.println(sizeof(array5));
}
//////////////////////////////////////
}
///////////////
void loop() {
}
/*
*This sketch outputs images to persistence of vision led strips
*It uses FastLed to drive APA102 leds, sending colour values from
*arrays held in flash memory (designated by 'const'). You need to
*set the number of slices you have made your image into,
*e.g. bmp image of 60 pixels high by 150 wide
* would give 60 num_leds and
* 150 slices (number of slices you have made your image into)
*/
#include <SPI.h>
#include "SerialFlash.h"
#include "FastLED.h"
#define FlashChipSelect 10
#define NUM_LEDS 56 //number of leds in strip length on one side
#define DATA_PIN 23//7 = second hardware spi data
#define CLOCK_PIN 21//14 = second hardware spi clock
CRGB leds[NUM_LEDS];
unsigned int array1[240*NUM_LEDS];
unsigned int pictureNumber = 11;
char filename[] = "pXX.bin";
const unsigned int arrBlack[] = { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, };
int numberOfSlices = 1;
///////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN>(leds, NUM_LEDS);
SerialFlash.begin(FlashChipSelect);
delay(100);
Serial.println("setup");
}
//////////////////////////////////////////////////////////////////
void loop() {
loadPicture(pictureNumber); //load picture number=pictureNumber to array 1
PoiSonic(8000,array1); //call method, with duration to show (8sec) and array name.
pictureNumber=pictureNumber+1;
}
//////////////////////////////////////////////////////////////
void PoiSonic(unsigned long time, const unsigned int array[]){
unsigned long currentTime = millis();
while (millis()< currentTime + (time)) {
int f= numberOfSlices;
int z; //a counter
int j=NUM_LEDS;
for (int x=0;x<f;x++){
for(z=NUM_LEDS;z>0;z--){
leds[z-1]=array[x+((j-z)*f)];}
FastLED.show();
delayMicroseconds(1400); //may need to increase / decrease depending on spin rate
}
delayMicroseconds(1000); //may need to increase / decrease depending on spin rate
}
}
/////////////////////////////////////////////////////////////
void loadPicture(int num){
char XX[2];
sprintf(XX, "%d", num);
filename[1]=XX[0];
filename[2]=XX[1];
SerialFlashFile file;
if (SerialFlash.exists(filename))
{}
else
{
pictureNumber = 11;
filename[1]=1+'0';
filename[2]=1+'0';
}
file = SerialFlash.open(filename);
if (file)
{
file.read(array1, sizeof(array1));
numberOfSlices = file.size()/4/NUM_LEDS;
Serial.println("----sprawdzenie otwierania-----");
Serial.println(numberOfSlices);
Serial.println(filename);
Serial.println(file.size());
}
file.close();
}
What was the issue, so that others might avoid it? Was it the array?
@mortonkopf, I ran into the same problem in post #55. Moving the Loop() after PoiSonic() solved it for me. I'm using 1.6.9.
// Add this prototype before the function is called
void PoiSonic(unsigned long time, const unsigned int array[]); // first line of function with a semi-colon not an open brace
loop() {
void PoiSonic( Xtime, Xarray );
}
void PoiSonic(unsigned long time, const unsigned int array[]){
// real function declared here
}
// Add this prototype before the function is called
void PoiSonic(unsigned long time, const unsigned int array[]); // first line of function with a semi-colon not an open brace
loop() {
void PoiSonic( Xtime, Xarray );
}
void PoiSonic(unsigned long time, const unsigned int array[]){
// real function declared here
}
@defragster, this also works. However I prefer moving the Loop(). Maintaining the prototype, as well as the function, is annoying. If I change from int to char in the function will I have to remember to do the same in the prototype? Why the change in the Arduino IDE?
the currently displayed pattern has to reside in ram, correct?
how much will there be left (approximately) when the SPI and FastLED libraries are included?
because it's also SPI.