I couldn't find any solution on the web. I was wondering how to change the data inside a progmem.
#include "Arduino.h"
#include <avr/pgmspace.h>
//#include "world.h"
//#include "troll.h"
//#include "uewar.h"
#define SpinInterrupt 0
#define SpinInput 2
//Define cols/rows to ports
//column +
#define col0 3
#define col1 4
#define col2 5
#define col3 6
#define col4 7
#define col5 8
#define col6 9
#define col7 10
#define col8 11
//row -
#define row0 12
#define row1 13
#define row2 14
#define row3 15
#define row4 16
#define row5 17
#define row6 18
#define row7 19
#define LEDOrientation false
const int ImageColumns=131;
int ImageRows=72;
const int LEDEights=9;
#define ImageColumns 131
#define ImageRows 72
#define LEDEights 9
prog_uint8_t Image[ImageColumns][LEDEights] PROGMEM = {
{
B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 }
, {
B11111111, B10110111, B10111001, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 }
};
volatile unsigned long microsPerPixelColumn = 10000;
volatile unsigned long microsPerPixelEight = 0;
volatile unsigned long lastSpinTime = 0;
volatile int column = 0;
volatile int row = 0;
volatile int LEDEight = 0;
volatile int CurrentColumns = 0;
unsigned long inturruptDebounce = 80;
bool bStop;
int eightpins[9] = {col0, col1, col2, col3, col4, col5, col6, col7, col8};
int pins[72][2] = {{col0, row0},
{col0, row1},
{col0, row2},
{col0, row3},
{col0, row4},
{col0, row5},
{col0, row6},
{col0, row7},
{col1, row0},
{col1, row1},
{col1, row2},
{col1, row3},
{col1, row4},
{col1, row5},
{col1, row6},
{col1, row7},
{col2, row0},
{col2, row1},
{col2, row2},
{col2, row3},
{col2, row4},
{col2, row5},
{col2, row6},
{col2, row7},
{col3, row0},
{col3, row1},
{col3, row2},
{col3, row3},
{col3, row4},
{col3, row5},
{col3, row6},
{col3, row7},
{col4, row0},
{col4, row1},
{col4, row2},
{col4, row3},
{col4, row4},
{col4, row5},
{col4, row6},
{col4, row7},
{col5, row0},
{col5, row1},
{col5, row2},
{col5, row3},
{col5, row4},
{col5, row5},
{col5, row6},
{col5, row7},
{col6, row0},
{col6, row1},
{col6, row2},
{col6, row3},
{col6, row4},
{col6, row5},
{col6, row6},
{col6, row7},
{col7, row0},
{col7, row1},
{col7, row2},
{col7, row3},
{col7, row4},
{col7, row5},
{col7, row6},
{col7, row7},
{col8, row0},
{col8, row1},
{col8, row2},
{col8, row3},
{col8, row4},
{col8, row5},
{col8, row6},
{col8, row7}
};
const char s[2] = "~"; //for cutting;
String inData;
char inData2[100]; // Allocate some space for the string
char *token;
char *token2;
char *token3;
char x1[100];
char x2[100] = " This is ACRLDS v2.0 :) ";
char x3[100];
String tryData = "";
char inChar=-1; // Where to store the character read
byte index = 0; // Index into array; where to store the character
// sensor setup
void setup()
{
pinMode(SpinInput, INPUT); //Reed switch
pinMode(col0, OUTPUT);
pinMode(col1, OUTPUT);
pinMode(col2, OUTPUT);
pinMode(col3, OUTPUT);
pinMode(col4, OUTPUT);
pinMode(col5, OUTPUT);
pinMode(col6, OUTPUT);
pinMode(col7, OUTPUT);
pinMode(col8, OUTPUT);
pinMode(row0, OUTPUT);
pinMode(row1, OUTPUT);
pinMode(row2, OUTPUT);
pinMode(row3, OUTPUT);
pinMode(row4, OUTPUT);
pinMode(row5, OUTPUT);
pinMode(row6, OUTPUT);
pinMode(row7, OUTPUT);
CurrentColumns = ImageColumns;
lastSpinTime = micros();
Clear();
for(int j = 0; j < ImageRows; j++)
{
Clear();
digitalWrite(pins[j][0], !LEDOrientation);
digitalWrite(pins[j][1], LEDOrientation);
delay(30);
}
attachInterrupt(SpinInterrupt, spinInterrupt, FALLING);
}
bool inInterrupt = false;
unsigned long spinTime = 0;
void spinInterrupt()
{
if(lastSpinTime == 0)
{
lastSpinTime = micros();
return;
}
if(!inInterrupt && micros() - lastSpinTime > inturruptDebounce)
{
inInterrupt = true;
unsigned long newSpinTime = micros() - lastSpinTime;
if(spinTime != 0 && (newSpinTime > spinTime*2 || newSpinTime < spinTime/2))
{
inInterrupt = false;
return;
}
spinTime = newSpinTime;
microsPerPixelColumn = spinTime / CurrentColumns;
microsPerPixelEight = microsPerPixelColumn / LEDEights;
lastSpinTime = micros();
inInterrupt = false;
}
void loop()
{
if(Comp("globe~")==0){
/************************I WANT TO INSERT THE NEW VALUE OF PROGMEM HERE:******************/
prog_uint8_t Image[ImageColumns][LEDEights] PROGMEM = {
{
B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 }
, {
B11111111, B10110111, B10111001, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111
};
}
}
for(column = 0; column < CurrentColumns; column++)
{
for(LEDEight = 0; LEDEight < LEDEights ; LEDEight++)
{
DrawLEDGroupsAtOnce(LEDEight, column);
}
}
}
char Comp(char* This) {
while(Serial.available()) {
inChar = Serial.read();
inData.concat(inChar);
}
strcpy(inData2, inData.c_str());
token = strtok(inData2, s);
strcpy(x1,token);
token = strtok(NULL, s);
strcpy(x2,token);
token = strtok(NULL, s);
strcpy(x3,token);
if (strcmp(x3,This) == 0) {
Serial.println(x1);
Serial.println(x2);
Serial.println(x3);
inData = "";
inChar = '\0';
return(0);
}
else {
return(1);
}
}
void DrawLEDGroupsAtOnce(int eight, int column)
{
prog_uint8_t imageEights = pgm_read_byte(&(Image[column][eight]));
PORTB = (PORTB | B00110000) & ((imageEights << 4) | B11001111);
PORTC = (PORTC | B00111111) & ((imageEights >> 2) | B11000000);
digitalWrite(eightpins[eight], !LEDOrientation);
if (microsPerPixelEight > 20)
delayMicroseconds(microsPerPixelEight - 17);
digitalWrite(eightpins[eight], LEDOrientation);
}
void Clear()
{
for(int j = 0; j < ImageRows; j++)
{
digitalWrite(pins[j][0], LEDOrientation);
digitalWrite(pins[j][1], !LEDOrientation);
}
}
here is the error:
sketch_feb18b.ino: In function 'void spinInterrupt()':
sketch_feb18b:511: error: a function-definition is not allowed here before '{' token
sketch_feb18b:851: error: expected `}' at end of input
PS: I've cutted some portions of the data inside the progmem because the forum gives me an error. 9500 is the max chars.