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;
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;
pinMode(LCDResetpin,OUTPUT); //LCD Reset
digitalWrite(LCDResetpin,HIGH); //Must be kept high. Low to reset LCD.
delay(2000); //Wait for display power
fontcolor = getcolor(255,255,255);
timecolor = fontcolor;
strcpy_P(buffer, (char*)pgm_read_word(&(string_table))); //Startup //This comes from the string table and should be unimportant
currentbutton = debounce(lastbutton);
//Check if burron pressed. Count Millis until released.
if (lastbutton == LOW && currentbutton == HIGH)
startmillis = millis();
endmillis = millis();
}while(digitalRead(buttonpin) == HIGH);
//Check to see if this is the startup button press.
if ((initialized == false) && (endmillis - startmillis > powerontime))
initialized = true;
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);
//Handle countdown issues.
if (timesec > 0)
timesec -= 1;
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.
timecolor = fontcolor; //If more than 1 minute remaining, countdown timer is white.
if ((bombteam = 1) || (bombteam = 2))
if (bombsec > 0)
bombsec -= 1;
bombsec = 59;
bombmin -= 1;
scoremillis = millis();
lastbutton = currentbutton;
// Routine to receive game setup data.
bombteam = 1;
gamemode = 11;
timesec = 20;
timemin = 1;
bombmin = 2;
bombsec = 0;
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.
if (gamemode >= 10)
sprintf(timetext,"%2d:%02d", timemin, timesec);
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);
I am stuck!