OK, I'm new to forums.... but I def need help because i'm having issues with my arduino locking up...
I have an array of unsigned longs stored in progmem, and what my code does is reads the values of the longs and spits out the data through digitalWrite commands on certain pins after reading the time interval to change the output states also stored in the array. This sequence of events is triggered by pressing a button declared in the code.
Everything seems to be running perfectly fine except sometimes the arduino locks up randomly. I'm using an Arduino Mega 2560 for this project. I don't believe I'm passing any of this data through ram because i'm using progmem, but now i'm just completely lost and i don't know what to do...
The array structure is {just a counter number i don't use, the time interval, output bank set 1, output bank set 2, output bank set 3}
Thanks in advance!
prog_uint32_t ulButton1[602][5] PROGMEM =
{{ 0, 100, 0x3F9D,0x401,0x3FF0} ,
{ 1, 200, 0x3F9C,0x401,0x3FF0} ,
{ 2, 300, 0x3F9E,0x401,0x3FF0} ,
{ 3, 17500, 0x3F9A,0x401,0x3FF0} ,
{ 4, 17600, 0x3F9A,0x2401,0x3FF0} ,
{ 5, 17700, 0x3F9A,0x3C01,0x3FE0} ,
{ 6, 17800, 0x3F9A,0x3C01,0x3FE2} ,
{ 7, 18000, 0x3F9A,0x3C01,0x3FE3} ,
////........
{ 595, 90000, 0x3F9D,0x401,0x3FFB} ,
{ 596, 90200, 0x3F9D,0x401,0x3FFD} ,
{ 597, 90300, 0x3F9D,0x401,0x3FFC} ,
{ 598, 90500, 0x3F9D,0x401,0x3FF8} ,
{ 599, 0, 0x0,0x0,0x0 }};
#include <avr/pgmspace.h>
unsigned long x = 0; //used as a counting variable for the array
#define BUTTON1 A9 //declares BUTTON1 as pin A9
unsigned long time = 0; //reference timing for array
unsigned char lastbutton1 = LOW; //variable to indicate button pressed state...
int readin = 1; //variable for allowing button pressing to not disturb a scenario
void setup(){
for (int i = 2; i < 43; i++){
pinMode(i,OUTPUT);
}
pinMode(BUTTON1,INPUT);
digitalWrite(BUTTON1,HIGH);
for (int j = 0; j < 14; j++){
digitalWrite(j+2,(pgm_read_dword(&ulButton1[0][2])>>j)&1);
}
for (int k = 0; k < 14; k++){
digitalWrite(k+16,(pgm_read_dword(&ulButton1[0][3])>>k)&1);
}
for (int l = 0; l < 14; l++){
digitalWrite(l+30,(pgm_read_dword(&ulButton1[0][4])>>l)&1);
}
}
void loop(){
if(digitalRead(BUTTON1) == LOW && readin == 1){
time=millis();
lastbutton1 = HIGH;
}
if(digitalRead(BUTTON1) == HIGH && lastbutton1 == HIGH){
readin = 0;
if(millis() == time + (pgm_read_dword(&ulButton1[x][1]))){
for (int j = 0; j < 14; j++){
digitalWrite(j+2,(pgm_read_dword(&ulButton1[x][2])>>j)&1);
}
for (int k = 0; k < 14; k++){
digitalWrite(k+16,(pgm_read_dword(&ulButton1[x][3])>>k)&1);
}
for (int l = 0; l < 14; l++){
digitalWrite(l+30,(pgm_read_dword(&ulButton1[x][4])>>l)&1);
}
x++;
if(pgm_read_dword(&ulButton1[x][1]) == 0){
lastbutton1 = LOW;
time = 0;
x = 0;
readin = 1;
}
}
}
}