Hello,
im trying to "convert" a char array to a short array which is then supposed to be draw on my LCD-display using the UTFT library and its drawBitmap function.
The problem is, it doesnt.
Why do I do that? Well not a single SD-Card I tried (4 different) worked with any Library I tried (SD.h, SDFat.h, tinyFat) and after searching for MANY hours without finding any solution I came to the idea to use the Mega's 252kB flash memory, but that will only work if I get this working because I want to fit 20 images in there, with each being 13kB when stored as short I will run out of it pretty quick.
To the SD-Cards:
No, my wiring is not wrong and yes, I used the SD Card Formatter tool everyone tells you to use.
To explain the code a bit:
every value stored in the char array is shifted left a total of 8 times(from 0 to 7) and after every shift compared to 0x1, if it returns true then 0xFFFF is written a dummy array, else 0x0000.
To keep the RAM from exploding the drawBitmap function is run after the dummy array is filled with 136 (W*2) values and then overwrite them in the next call of my converter function.
Tried to check the contents of my dummy array using Serial.print but as expected it does not return anything...
PLEASE help me.
Greetings,
Tsarga
#include <avr/pgmspace.h>
#include <UTFT.h>
#define LED_A 45
#define H 96 // Height of the image
#define W 68 // Width of the image
#define DoubleRow W*2
#define DoubleRow_Bit DoubleRow/8
UTFT myGLCD(SSD1963_480, 44, 43, 42, 41);
int dummy[DoubleRow];
// this is the array i want to convert to a short
const unsigned char Airflow2[]PROGMEM = {
0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0,
0, 0, 0, 0, 15, 0, 0, 0, 1, 216, 0, 0, 0, 15, 0, 224,
96, 3, 216, 0, 0, 0, 15, 0, 224, 96, 3, 24, 0, 0, 0, 15,
1, 176, 0, 3, 24, 0, 0, 0, 15, 1, 176, 99, 103, 216, 60, 97,
134, 15, 1, 176, 99, 231, 216, 126, 97, 134, 15, 3, 24, 99, 131, 24,
231, 51, 204, 15, 3, 24, 99, 3, 24, 195, 51, 204, 15, 7, 252, 99,
3, 24, 195, 50, 76, 15, 7, 252, 99, 3, 24, 195, 30, 120, 15, 6,
12, 99, 3, 24, 231, 30, 120, 15, 12, 6, 99, 3, 24, 126, 12, 48,
15, 12, 6, 99, 3, 24, 60, 12, 48, 15, 0, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0,
0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0,
0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 15,
0, 0, 0, 0, 7, 240, 0, 0, 15, 0, 0, 0, 127, 248, 31, 128,
0, 15, 0, 0, 1, 128, 0, 0, 112, 0, 15, 0, 0, 6, 0, 0,
0, 12, 0, 15, 0, 0, 4, 0, 0, 0, 6, 0, 15, 0, 0, 8,
0, 0, 0, 1, 0, 15, 0, 0, 8, 0, 0, 0, 1, 128, 15, 0,
0, 8, 0, 0, 0, 1, 128, 15, 0, 0, 16, 0, 0, 0, 7, 0,
15, 0, 96, 16, 0, 0, 0, 24, 0, 15, 0, 240, 16, 0, 0, 0,
112, 0, 15, 1, 16, 16, 0, 0, 1, 128, 0, 15, 3, 16, 16, 0,
0, 7, 0, 0, 15, 2, 8, 16, 0, 0, 8, 0, 0, 15, 4, 12,
16, 0, 0, 112, 0, 0, 15, 4, 4, 16, 0, 0, 64, 0, 0, 15,
4, 4, 16, 0, 1, 129, 255, 192, 15, 8, 2, 16, 0, 1, 3, 0,
56, 15, 8, 3, 24, 0, 3, 4, 0, 6, 15, 8, 1, 8, 0, 4,
8, 0, 2, 15, 8, 1, 4, 0, 4, 16, 0, 1, 15, 8, 0, 130,
0, 4, 16, 0, 1, 15, 24, 0, 129, 128, 4, 32, 0, 0, 143, 16,
0, 192, 96, 8, 32, 0, 0, 143, 16, 0, 32, 28, 8, 64, 0, 0,
143, 16, 0, 56, 3, 8, 64, 0, 0, 143, 16, 0, 8, 1, 248, 64,
0, 0, 143, 16, 0, 4, 1, 4, 128, 0, 0, 143, 16, 0, 3, 195,
3, 128, 0, 0, 143, 8, 0, 0, 60, 1, 0, 0, 0, 143, 8, 0,
0, 4, 1, 0, 0, 0, 143, 8, 0, 0, 4, 1, 0, 0, 0, 143,
8, 0, 0, 4, 1, 0, 0, 0, 143, 8, 0, 0, 4, 1, 224, 0,
0, 143, 8, 0, 0, 14, 6, 30, 0, 0, 79, 8, 0, 0, 9, 4,
1, 0, 0, 79, 8, 0, 0, 16, 252, 0, 128, 0, 79, 8, 0, 0,
16, 134, 0, 224, 0, 79, 8, 0, 0, 16, 129, 192, 32, 0, 79, 8,
0, 0, 32, 128, 48, 24, 0, 79, 8, 0, 0, 33, 0, 12, 8, 0,
207, 4, 0, 0, 65, 0, 2, 8, 0, 143, 4, 0, 0, 65, 0, 1,
4, 0, 143, 2, 0, 0, 129, 0, 0, 132, 0, 143, 3, 0, 1, 6,
0, 0, 198, 0, 143, 0, 224, 6, 4, 0, 0, 66, 0, 143, 0, 31,
252, 12, 0, 0, 65, 1, 15, 0, 0, 0, 16, 0, 0, 65, 1, 15,
0, 0, 0, 112, 0, 0, 65, 129, 15, 0, 0, 0, 128, 0, 0, 64,
130, 15, 0, 0, 7, 0, 0, 0, 64, 70, 15, 0, 0, 12, 0, 0,
0, 64, 68, 15, 0, 0, 112, 0, 0, 0, 64, 120, 15, 0, 0, 192,
0, 0, 0, 64, 48, 15, 0, 7, 0, 0, 0, 0, 64, 0, 15, 0,
12, 0, 0, 0, 0, 128, 0, 15, 0, 12, 0, 0, 0, 0, 128, 0,
15, 0, 4, 0, 0, 0, 0, 128, 0, 15, 0, 3, 0, 0, 0, 1,
0, 0, 15, 0, 1, 128, 0, 0, 3, 0, 0, 15, 0, 0, 112, 0,
0, 12, 0, 0, 15, 0, 0, 15, 192, 255, 240, 0, 0, 15, 0, 0,
0, 127, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 15,
0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0,
};
// this is my function to convert my char array to a short array
void converter(unsigned short out[DoubleRow], char in[DoubleRow_Bit], int row) {
for (int x = DoubleRow_Bit * row; x < DoubleRow_Bit * (row + 1); x ++) {
////////////////////////////////////////////
if (( (in[x] >> 7) & 0x1) == 1) {
out[x * 8] = 0xFFFF;
}
else {
out[x * 8] = 0x0000;
}
//////////////////////////////////////////
if (( (in[x] >> 6) & 0x1) == 1) {
out[(x * 8) + 1] = 0xFFFF;
}
else {
out[(x * 8) + 1] = 0x0000;
}
////////////////////////////////////////////
if (( (in[x] >> 5) & 0x1) == 1) {
out[(x * 8) + 2] = 0xFFFF;
}
else {
out[(x * 8) + 2] = 0x0000;
}
////////////////////////////////////////////
if (( (in[x] >> 4) & 0x1) == 1) {
out[(x * 8) + 3] = 0xFFFF;
}
else {
out[(x * 8) + 3] = 0x0000;
}
////////////////////////////////////////////
if (( (in[x] >> 3) & 0x1) == 1) {
out[(x * 8) + 4] = 0xFFFF;
}
else {
out[(x * 8) + 4] = 0x0000;
}
////////////////////////////////////////////
if (( (in[x] >> 2) & 0x1) == 1) {
out[(x * 8) + 5] = 0xFFFF;
}
else {
out[(x * 8) + 5] = 0x0000;
}
////////////////////////////////////////////
if (( (in[x] >> 1) & 0x1) == 1) {
out[(x * 8) + 6] = 0xFFFF;
}
else {
out[(x * 8) + 6] = 0x0000;
}
////////////////////////////////////////////
if (( (in[x] >> 0) & 0x1) == 1) {
out[(x * 8) + 7] = 0xFFFF;
}
else {
out[(x * 8) + 7] = 0x0000;
}
Serial.print(out[(x * 8) + 0]);
Serial.print(", ");
Serial.print(out[(x * 8) + 1]);
Serial.print(", ");
Serial.print(out[(x * 8) + 2]);
Serial.print(", ");
Serial.print(out[(x * 8) + 3]);
Serial.print(", ");
Serial.print(out[(x * 8) + 4]);
Serial.print(", ");
Serial.print(out[(x * 8) + 5]);
Serial.print(", ");
Serial.print(out[(x * 8) + 6]);
Serial.print(", ");
Serial.println(out[(x * 8) + 7]);
//////////////////////////////////////////
}
}
void setup(void)
{
Serial.begin(115200);
pinMode(LED_A, OUTPUT);
digitalWrite(LED_A, HIGH);
// Setup the LCD
myGLCD.InitLCD();
myGLCD.clrScr();
}
void loop() {
//this loop will call the converter function and draw its results on my display, 2 lines each call
//in theory atleast....
for (int i = 0; i <= H / 2; i++) {
converter(dummy[DoubleRow], Airflow2[DoubleRow_Bit], i);
myGLCD.drawBitmap(0, 2 * i, W, 2, dummy);
}
delay(10000);
}