I agree that this shouldn't be happening but I have stripped out everything of no consequence and it still will not change that variable. I have moved all my strings to PROGMEM so I am fairly confident that this is not causing my problem. I have been trying to avoid posting a bunch of code so as not to scare people off but here goes:
I have left out the string setup at the top and the vast majority of the code but this is the part that is broken. If I dumb it way down and simply print to the HyperTerminal it works fine.
int bombteam = 0;
int gamemode = 0;
int team1score = 0;
int team2score = 0;
char team1scoretext[4];
char team2scoretext[5];
boolean gamestart = false;
int timesec = 10;
int timemin = 10;
int bombsec = 10;
int bombmin = 10;
const int LCDResetpin =13;
const int redpin = 12;
const int greenpin = 11;
const int buttonpin = 9;
boolean lastbutton = LOW;
boolean currentbutton = HIGH;
unsigned long startmillis = 0;
unsigned long endmillis = 0;
boolean initialized = false;
int powerontime = 3000;
unsigned long scoremillis = 0;
const unsigned int fontcolor = 65535;
unsigned int timecolor = 0;
unsigned int bombcolor = 0;
unsigned int tempcolor = 0;
void setup()
{
pinMode(redpin,OUTPUT);
pinMode(greenpin,OUTPUT);
pinMode(buttonpin,INPUT);
pinMode(LCDResetpin,OUTPUT); //LCD Reset
pinMode(8,OUTPUT);
digitalWrite(LCDResetpin,HIGH); //Must be kept high. Low to reset LCD.
randomSeed(analogRead(0));
Serial.begin(9600);
delay(2000); //Wait for display power
Serial.write(0x55); //Autobaud
getreply();
fontcolor = getcolor(255,255,255);
timecolor = fontcolor;
strcpy_P(buffer, (char*)pgm_read_word(&(string_table[2]))); //Startup //This comes from the string table and should be unimportant
writetext(5,5,2,fontcolor,1,1,buffer);
}
void loop()
{
//Debounce button
currentbutton = debounce(lastbutton);
//Check if burron pressed. Count Millis until released.
if (lastbutton == LOW && currentbutton == HIGH)
{
startmillis = millis();
do
{
endmillis = millis();
}while(digitalRead(buttonpin) == HIGH);
}
//Check to see if this is the startup button press.
if ((initialized == false) && (endmillis - startmillis > powerontime))
{
digitalWrite(redpin,HIGH);
digitalWrite(greenpin,LOW);
initialized = true;
delay(100);
initLCD();
delay(1000);
receivegamedata();
initgameLCD();
startmillis = endmillis;
}
//See if this is the start game press.
if ((initialized == true) && (endmillis - startmillis > 300))
{
gamestart = true;
startmillis = endmillis;
}
//Check every one second to update time.
//This currently also randomly assigns scores and bombteam color
if ((millis() - scoremillis > 1000) && gamestart == true)
{
long randomteam = random(3);
if (randomteam == 1)
{
bombteam = 1; //This simply doesn't happen
team1score += 100; //This works exactly as expected
sprintf(team1scoretext, "%d", team1score); //This works exactly as expected
writetext(60,34,0,fontcolor,1,1,team1scoretext); //This works exactly as expected
// Because the score updates on the LCD screen, I know this if loop is functioning. It just doesn't change the bombteam number?????? Both the initialized and gamestart variables are both set to a logical 1.
}
else if (randomteam == 2)
{
bombteam = 2; //Same as above
team2score += 100;
sprintf(team2scoretext, "%d", team2score);
writetext(60,49,0,fontcolor,1,1,team2scoretext);
}
//Handle countdown issues.
if (timesec > 0)
{
timesec -= 1;
}
else
{
timesec = 59;
timemin -= 1;
}
if ((timemin == 0) && (timesec <= 59))
{
timecolor = getcolor(255,0,0); //Sets countdown timer color to red once less than 1 minute remaining.
}
else
{
timecolor = fontcolor; //If more than 1 minute remaining, countdown timer is white.
}
if ((bombteam = 1) || (bombteam = 2))
{
if (bombsec > 0)
{
bombsec -= 1;
}
else
{
bombsec = 59;
bombmin -= 1;
}
}
updatetime();
scoremillis = millis();
}
lastbutton = currentbutton;
}
// Routine to receive game setup data.
void receivegamedata()
{
bombteam = 1;
gamemode = 11;
timesec = 20;
timemin = 1;
bombmin = 2;
bombsec = 0;
}
void updatetime()
{
char timetext[20];
sprintf(timetext,"%d",bombteam); // This is where I am printing the BombTeam number. It is whatever I set it to in the Receive data function until I start the game then it goes to a 1 and never changes.
writetext(2,2,1,fontcolor,1,1,timetext);
if (gamemode >= 10)
{
sprintf(timetext,"%2d:%02d", timemin, timesec);
writetext(18,78,2,timecolor,1,1,timetext);
sprintf(timetext,"%2d:%02d", bombmin, bombsec);
if (bombteam == 0)
{
bombcolor = fontcolor;
}
if (bombteam == 1)
{
bombcolor = getcolor(0,0,255);
}
if (bombteam == 2)
{
bombcolor = getcolor(51,204,51);
}
writetext(75,78,2,bombcolor,1,1,timetext);
}
else
{
writetext(24,71,2,timecolor,2,2,timetext);
}
}
I am stuck!