boolean reports an int ???

I have a simple piece of code to run two buttons with some denouncing. Other than the variable names these code bits are basically the same. However one works and the other does not. That is until i remove the thumping variable from the first. when i serial printed both the bools i found one reporting as normal and the other reporting as a randomish number between 10 and 300. What on earth is going on? Perhaps my mega is on its death kneel?

Code?

/********************************
 ** DataThing - iCoat v 2.00 **
 ********************************/
/*
 v2.00
   -Rewrite of code to support live data feeds and Data addressing
 v1.05
 -updated serial sending to prep for sending data to beaglebone black instead of arduino sending unit
 v1.04
 -updated e24 to match pump settings and fire at 300 psi out of balence
 v1.03
 -reduced mem usage by making temp sensors use int instead of float.
 -Removing ethernet and sd abilitys to be moved to a second arduino inorder
  to free up processor for more demanding tasks.
 - updated scale code to only take in values of 100.0 lbs or more to eliminate read errors.
 v1.02
 -updated the entire scale code
 v1.01
 -fixed pressure read bug.Now reading 20x per sec instead of 100x
 -added digitalReadFast instead of the much slower digitalRead
 -added the volitile tag to vars that get modified with the ISR's
 -slowed down the button press isr to read only once per .1 secs
 -changed button and thump inputs to use different loops and slowed
 down the timer to lighten the processing load.
 -fixed totally broken scale code. Should now report proper weights
 -moved pressure code into ISR to fix timing issues.
 -moved light operation code into ISR to make more consistant timing
 */
 
 
/*
Addressing Lables

*/

#include <SPI.h>
#include <DHT.h>
#include<digitalWriteFast.h>

// Device Addressing Definitions=======================
String DATA_ADD_PRESSUREAB = "4.1.";
String DATA_ADD_DHT11IN = "4.2.";
String DATA_ADD_DHT11OUT = "4.3.";
String DATA_ADD_SCALE1 = "4.4.";
String DATA_ADD_SCALE2 = "4.5.";
String DATA_ADD_SCALE3 = "4.6.";
String DATA_ADD_THUMP = "4.7.";
String DATA_ADD_BUTTONA = "4.8.";
String DATA_ADD_RUNTIME = "4.9.";
String DATA_ADD_RACKTHUMPS ="4.10.";


// DHT11 Temprature Sensor Defenitions=======================
#define DHTPININ 31     // what pin we're connected to
#define DHTPINOUT 30     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPININ, DHTTYPE);
DHT dht2(DHTPINOUT, DHTTYPE);
// Pin Declerations===============================
const int thumpPin = 32;
const int lg = 22;
const int ly = 23;
const int lr = 24;
const int LCDPin = 25;
const int buttonPin = 35;
const int e24pin = 28;

// Variable Declerations===============================
volatile int p[2]= {};
int numOfPressureSen = 4;
const char pin[4] = {A0,A1,A2,A3};
boolean thumping = false;
boolean buttonPressed = false;
boolean buttonToggle = false;
boolean addScaleFlag = true;
boolean oneTimeToggle = false;
volatile long thumpCounter;
volatile long thumpPastTimer;
volatile long buttonPastTimer;
volatile int e24State = 0;
volatile int multiplier = -1;
volatile int lightTimer;
volatile long startThumpCounter;
volatile boolean lSwitch;
volatile boolean runningLights = true;


// SETUP FUNCTION===============================
void setup(){
  Serial.begin(115200);
  Serial1.begin(9600);
  Serial2.begin(9600);
  Serial3.begin(9600);
  dht.begin(); 
  dht2.begin();
  pinMode(LCDPin,OUTPUT);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  pinMode(lr, OUTPUT);
  pinMode(ly, OUTPUT);
  pinMode(lg, OUTPUT);
  digitalWriteFast(lr, HIGH);
  digitalWriteFast(ly, HIGH);
  digitalWriteFast(lg, HIGH);
  pinMode(e24pin, OUTPUT);
  digitalWriteFast(e24pin,HIGH);
  digitalWriteFast(thumpPin,LOW);
  digitalWriteFast(buttonPin,LOW);
  digitalWriteFast(LCDPin,HIGH);
  timer1();
  timer4();
  timer5();
}

//=======================================Reads Pressure and handels E24 Errors
ISR(TIMER1_COMPA_vect) {
  String pressure = DATA_ADD_PRESSUREAB;
  for(int r =0; r<numOfPressureSen; r++){
    p[r] = analogRead(pin[r]);
    p[r] = map(p[r],0,1023,0,3100);
    pressure += p[r];
    pressure += '.';
  }
  if (p[0] - p[1] < -290 || p[0] - p[1] > 290 || p[2] - p[3] < -290 || p[2] - p[3] > 290){
    pressure +='E';
    if(digitalReadFast(e24pin) == HIGH) {
      digitalWriteFast(e24pin,LOW);
      digitalWriteFast(lr, LOW);
      e24State = 1;
    }
  }
  else if(digitalReadFast(e24pin) == LOW){
   e24State = 0;
   digitalWriteFast(e24pin,HIGH);
   digitalWriteFast(lr, HIGH);
  }
 // Serial.println(pressure);
}
//=======================================Runs Thump counter and Button presses
ISR(TIMER4_COMPA_vect) {  
  unsigned long thumpTimer = millis();  
  if (thumpTimer - thumpPastTimer > 30){
    thumpPastTimer = thumpTimer;
    if (thumping == false && digitalReadFast(thumpPin) == HIGH) {
      digitalWriteFast(LCDPin, LOW);
      thumping = true;
      Serial.println(DATA_ADD_THUMP);
    }
    else if (thumping == true && digitalReadFast(thumpPin) == LOW){
      digitalWriteFast(LCDPin, HIGH);
      thumping = false;
    }
  }
  
    //-----------------------------------------
  unsigned long buttonTimer = millis();  
  if (buttonTimer - buttonPastTimer > 30){
    buttonPastTimer = buttonTimer;
    if (buttonPressed == false && digitalReadFast(buttonPin) == HIGH){ 
      buttonPressed = true;
      buttonToggle = buttonToggle^1;
      oneTimeToggle = true;
      addScaleFlag = false;
      Serial.println(DATA_ADD_BUTTONA);
    }
    else if (buttonPressed == true && digitalReadFast(buttonPin) == LOW){
      buttonPressed = false;
    }
  }
  
}
//=======================================Runs The Lights and E24 Timing
ISR(TIMER5_COMPA_vect) { // this event happens once every 1 seconds
  multiplier ++;
  if(buttonToggle == 1 && lightTimer < 500){
    lightTimer++;
  }
  if(lSwitch == true){
    lSwitch = false;
  }
  
  
  if(buttonToggle == 1 && e24State == 0 && lSwitch == false){
    if (oneTimeToggle == true){
      digitalWriteFast(lr,LOW);
      digitalWriteFast(ly,LOW);
      digitalWriteFast(lg,LOW);
      startThumpCounter = thumpCounter;
      lightTimer = 0;
      oneTimeToggle = false;
      runningLights = true;
    }
    if(lightTimer == 1){
      digitalWriteFast(lr,HIGH);
      digitalWriteFast(ly,HIGH);
      digitalWriteFast(lg,HIGH);
      lSwitch = true;
    }
    if(lightTimer == 4){
      digitalWriteFast(lg,HIGH);
      digitalWriteFast(ly,HIGH);
      digitalWriteFast(lr,LOW);
      lSwitch = true;
    }
    else if (lightTimer == 6){
      digitalWriteFast(lr,HIGH);
      digitalWriteFast(ly,LOW);
      lSwitch = true;
    }
    else if (lightTimer == 8){
      digitalWriteFast(ly,HIGH);
      digitalWriteFast(lg,LOW);
      lSwitch = true;
    }}
    
  else if(buttonToggle == 0 && lSwitch == false){
    if(oneTimeToggle == true){
      digitalWriteFast(lr,HIGH);
      digitalWriteFast(ly,HIGH);
      digitalWriteFast(lg,HIGH);
      oneTimeToggle = false;
      if(lightTimer > 8 && runningLights == true){
        
        runningLights = false;
        String runTime = DATA_ADD_RUNTIME;
        runTime += lightTimer;
        Serial.println(runTime);
        lightTimer = 0;
        String rackThumps = DATA_ADD_RACKTHUMPS;
        rackThumps += thumpCounter - startThumpCounter;
        Serial.println(rackThumps);
      }}}}
  
// PROGRAM LOOP===============================
void loop(){
  //-----------------------------------------
  if(addScaleFlag == false){
    addScaleFlag = true;
    getScales();
  }
  //----------------------------------------- 
  if (multiplier == 60){
    int humIn = dht.readHumidity();
    int tempIn = dht.readTemperature();
    int humOut = dht2.readHumidity();
    int tempOut = dht2.readTemperature();
    
    String ti = DATA_ADD_DHT11IN;
    ti += tempIn;
    ti +='.';
    ti += humIn;
    Serial.println(ti);
    String to = DATA_ADD_DHT11OUT;
    to += tempOut;
    to +='.';
    to += humOut;
    Serial.println(to);
  }
}


void timer5(){
//Timer 1:Set to 1 second intervals
  TCCR5A = 0;
  TCCR5B = 0;
  TCNT5  = 0;
  OCR5A = 15624;// ((interval in seconds) * .000064)-1 gives ocr value with a max value of 65536.
  TCCR5B |= (1 << WGM52);
  TCCR5B |= (1 << CS52) | (1 << CS50);  
  TIMSK5 |= (1 << OCIE5A);
}
void timer4(){
  //Timer 4: Set to .1 second intervals
  TCCR4A = 0;
  TCCR4B = 0;
  TCNT4  = 0;
  OCR4A = 1562;
  TCCR4B |= (1 << WGM42);
  TCCR4B |= (1 << CS42) | (1 << CS40);
  TIMSK4 |= (1 << OCIE4A);
}

void timer1(){
//Timer 1. 16 bit Timer. Max value 65536
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;
  OCR1A = 3124;//set to .2 seconds or 5x per sec
  TCCR1B |= (1 << WGM12);
  TCCR1B |= (1 << CS12) | (1 << CS10);
  TIMSK1 |= (1 << OCIE1A);
}

specifically the code inside of ISR timer 4

when I seperate this code out it works perfectly…

#include<digitalWriteFast.h>

volatile long thumpCounter;
volatile long thumpPastTimer;
volatile long buttonPastTimer;
const int buttonPin = 35;
const int thumpPin = 32;
// Device Addressing Definitions=======================
String DATA_ADD_PRESSUREAB = "4.1.";
String DATA_ADD_DHT11IN = "4.2.";
String DATA_ADD_DHT11OUT = "4.3.";
String DATA_ADD_SCALE1 = "4.4.";
String DATA_ADD_SCALE2 = "4.5.";
String DATA_ADD_SCALE3 = "4.6.";
String DATA_ADD_THUMP = "4.7.";
String DATA_ADD_BUTTONA = "4.8.";
String DATA_ADD_RUNTIME = "4.9.";
String DATA_ADD_RACKTHUMPS ="4.10.";

boolean thumping = false;
boolean buttonPressed = false;
void setup() {
Serial.begin(9600);
timer1();
}

void timer1(){
//Timer 1. 16 bit Timer. Max value 65536
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;
  OCR1A = 1562;//set to .2 seconds or 5x per secA
  TCCR1B |= (1 << WGM12);
  TCCR1B |= (1 << CS12) | (1 << CS10);
  TIMSK1 |= (1 << OCIE1A);
}

ISR(TIMER1_COMPA_vect) {  
  unsigned long thumpTimer = millis();  
  if (thumpTimer - thumpPastTimer > 30){
    thumpPastTimer = thumpTimer;
    if (thumping == false && digitalReadFast(thumpPin) == HIGH) {
      thumping = true;
      Serial.println(DATA_ADD_THUMP);
    }
    else if (thumping == true && digitalReadFast(thumpPin) == LOW){
      thumping = false;
    }
  }
  
    //-----------------------------------------
  unsigned long buttonTimer = millis();  
  if (buttonTimer - buttonPastTimer > 30){
    buttonPastTimer = buttonTimer;
    if (buttonPressed == false && digitalReadFast(buttonPin) == HIGH){ 
      buttonPressed = true;
      Serial.println(DATA_ADD_BUTTONA);
    }
    else if (buttonPressed == true && digitalReadFast(buttonPin) == LOW){
      buttonPressed = false;
    }
  }
  
}


void loop() {
  // put your main code here, to run repeatedly:

}

Xzeion: I have a simple piece of code ...

You're using interrupts, and hitting hardware timer registers directly. That's not what I would call simple code.

Quite a lot of code there:

Which two booleans? Are where is the code that prints them? And what does it print? I don't see INPUT_PULLUP on the button pins either - they have pullups/downs?

Xzeion:
I have a simple piece of code to run two buttons with some denouncing. Other than the variable names these code bits are basically the same. However one works and the other does not. That is until i remove the thumping variable from the first. when i serial printed both the bools i found one reporting as normal and the other reporting as a randomish number between 10 and 300. What on earth is going on? Perhaps my mega is on its death kneel?

I suspect you are running out of memory. Since you only ever set thumping and buttonPressed to true or false, it is clear that SOMETHING is clobbering one or the other (I gather you are printing out those two booleans, and one of them it showing random numbers that are not the compiler-defined true or false). If my assumptions are wrong, please let me know.

Nothing eats memory like the String class and its operations.