I have almost finished my most ambitious project yet, with some help from you guys along the way.
It is an inline hockey scoreboard, with 2 teamnames of eight 7x5 LED arrays, plus a whole load of bcd switches for scores, penalties, players number, period etc.
There is also an LCD display and buttons to set the teamnames, or select from a library of previous names. Thats working fine.
When I transmit to the scoreboard, a 22 or 23 byte message is sent with a digit to say if it is a number command ( 35 or # ) or a letter command ( 42 or * ) followed by the appropriate data.
It starts well enough, you can set both the teamnames, and the age group display, but as soon as I send a score update, or set time, the array that I have stored the letters in becomes corrupt, and puts one of the number data into one of my stored letter data. Which gives a strangely spelt new name.
here is the main loop, with a note to show where the problem arises , the buf[2] of the number data, somehow gets written to the buf[21] of the letter array.
( I monitored the free memory and there are 372 bytes spare )
I have attached the whole code, its really messy and needs tidying up when I can get some free time.
I think I have overlooked something stupid as usual, anybody spot it ?
void loop(){
if ( standby == HIGH ) {
blankalpha (); // clear teamnames
blanknumbers (); // clear numbers
}
else {
showpenalties ();
}
checktime (); // clock countdown
swapdisplay(); // switch alpha displays between teamname and age group
uint8_t buf[VW_MAX_MESSAGE_LEN]; // get message
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
Serial.println("Got: "); // Show on PC for debugging
Serial.print(" buflen = ");
Serial.println( int (buflen));
for ( int h = 0; h <=buflen-1; h++ ) { Serial.print(" buffer = ");
Serial.print(h); Serial.print( " = "); Serial.println( int(buf [h]));
}
if ( buf [0] == thisPin ) { // checking device number
Serial.println(" pins match ");
standby = LOW; // wake up board
if ( buf [1] == 42 ) { // = * ALPHA DATA COMING IN
for ( int y = 2; y <=22; y++ ) {
letterstore [y] = buf [y]; // save incoming names as buf will be changing with scores etc
Serial.print(" letterstore "); Serial.print(y);
Serial.print(" = "); Serial.println(char ( letterstore [y ]));
} // ***** at this point letterstore 21 is correct as received in the buffer unless
// a number button has been pressed, n which case it changes to the new buf[2] value ( key )*****
group = LOW; //
showteamnames ();
} // end of if ( buf [1] == '*' )
//***************************************************************************
if ( buf [1] == 35 ) // = # NUMERIC DATA INCOMING
{
key = buf [2];
Serial.print(" key = ");
Serial.println( int (key));
for ( int s = 1; s<= 19; s++ ) {
rxnumb [s] = buf [s+2] ;
Serial.print(" rxnumb ");
Serial.print(s);
Serial.print(" = ");
Serial.println( int ( rxnumb [s]));
penminT = rxnumb[7];
penminU = rxnumb[8];
}
sortnumbers ();
refreshpenalties ();
} // end of if ( buf [1] == '35' ) // NUMERIC DATA INCOMING
}
Serial.print("freeMemory()=");
Serial.println(freeMemory());
} // end of if message
} // end loop
ap9rxforum.pde (36.4 KB)