Touch process code stops voltage reference from working

i have been wondering why my voltage reference code wasn't working when included into my main code, when it works fine run on its own, i have broken my project and find that when i don't call the code to process the touches on the the touchscreen that the voltage reference works fine.

But i can't see why the touch code stops the voltage code from running

See below for system setup and voltage code

// web: http://www.henningkarlsen.com/electronics
//
//

#include <UTFT.h>
#include <ITDB02_Touch.h>
#include <avr/pgmspace.h>
#include <drawpage>
#include <touch>
#include <gps>
#include <Servo.h>
Servo servoMain; // Define our Servo

#include <Adafruit_GPS.h>
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
  // Older Arduino IDE requires NewSoftSerial, download from:
  // http://arduiniana.org/libraries/newsoftserial/
 #include <NewSoftSerial.h>
 // DO NOT install NewSoftSerial if using Arduino 1.0 or later!
#endif
Adafruit_GPS GPS(&Serial1);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO  true

// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy

// Declare which fonts/icons to be using
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
extern uint8_t SevenSegNumFont[];
extern unsigned int down[576];
extern unsigned int up[576];
const int systembattpin = A8; // pin that the sensor is attached to
const int controlbattpin = A9;
float voltage1;
float voltage2;
int pos = 60;

// Uncomment the next two lines for the ITDB02 Mega Shield
UTFT myGLCD(ITDB32S,38,39,40,41);   // Remember to add ASPECT_16x9 if you are using an ITDB02-3.2WC!
ITDB02_Touch  myTouch(6,5,4,3,2);

int x, y;
int page = 0;

void setup()
{
  //////////////////////////gps setup///////////////////////////////
      
  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  Serial.begin(115200);
  Serial.println("Adafruit GPS library basic test!");

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  
  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // the nice thing about this code is you can have a timer0 interrupt go off
  // every 1 millisecond, and read data from the GPS for you. that makes the
  // loop code a heck of a lot easier!
  useInterrupt(true);

  delay(1000);
  // Ask for firmware version
  Serial.println(PMTK_Q_RELEASE);
  
  /////////////////////////////////////////////////////////////////////////////
  
  servoMain.attach(8); // servo on digital pin 8
  // Initial setup
  myGLCD.InitLCD(PORTRAIT);
  myGLCD.clrScr();
  myTouch.InitTouch(PORTRAIT); //LANDSCAPE
  myTouch.setPrecision(PREC_HI);
  box();
  mainscr();
 
 ////////////////////////Status bars/////////////////////////////////////////
   myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (0, 26, 239, 0);
  myGLCD.fillRoundRect (0, 26, 239, 0);
  myGLCD.setFont(SmallFont);
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(255, 255, 255);
  myGLCD.print("Bike System", CENTER, 2);
  myGLCD.print("20:05:30", 10, 14);
  myGLCD.print("12/09/12", 170, 14);
  
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (0, 293, 239, 319);
  myGLCD.fillRoundRect (0, 293, 239, 319);
  myGLCD.setFont(SmallFont);
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(255, 255, 255);
  myGLCD.print("Battery status", CENTER, 294);
  myGLCD.print("System", 4, 306);
  myGLCD.print("Control", 130, 306);
  myGLCD.setColor(255, 0, 0);
  myGLCD.print("v", 95, 306);	
  myGLCD.print("v", 225, 306);
  
 /////////////////////////////////////////////////////////////////////////////
 
  page = 0;
}

void getbattstatus()
{
    // read the input on analog pin 8:
    int sensorValue = analogRead(A8);
      // read the input on analog pin 9:
  int sensorValue1 = analogRead(A9);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 8.4V):
  float voltage1 = ((sensorValue * 1.68) * (5.0 / 1023.0));
 // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 8.4V):
  float voltage2 = ((sensorValue * 1.68) * (5.0 / 1023.0));
  
  myGLCD.setFont(SmallFont);
  myGLCD.setColor(255, 0, 0);

  myGLCD.printNumF(voltage1, 1, 60, 306, '.', 3, ' ');
  myGLCD.printNumF(voltage2, 1, 190, 306, '.', 3, ' ');
}

void loop()
{
  getbattstatus();
  gpsloop();
}

the touch process code is on a separate tab and i have been calling in the void loop() using touch();

see touch code below

void touch()
{
  while (true)
  {
    if (myTouch.dataAvailable())

    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();

      //page 0 - Main menu

      if (page == 0){

        //Button: Go Ride        
        if ((y>=40) && (y<=110) && (x>=0) && (x<=239)){
          page = 1;
          box();
          ridescr();
         
        }

        //Button: Settings   
        else if ((y>=130) && (y<=200) && (x>=0) && (x<=239)){  
          page = 2;
          box();
          settingsscr();
          
        } 

        //Button: About    
        else if ((y>=220) && (y<=290) && (x>=0) && (x<=239)){
          page = 3;
          box();
          aboutscr();
        }
      }

      // page 1 - Go ride 
      if (page == 1){

        //122, 116, 234, 200 125/140 button
        
        if ((y>=116) && (y<=200) && (x>=122) && (x<=234)){
         servoMain.write(180);
        }
      }
      // page 2 - Settings 

      if (page == 2){

        //button1 5, 29, 117, 111
        if ((y>=29) && (y<=111) && (x>=5) && (x<=117)){
          page = 4;
          box();
          stsb1();
        }

        //button2 122, 29, 234, 111
        else if ((y>=29) && (y<=111) && (x>=122) && (x<=234)){
          page = 5;
          box();
          stsb2();
        }

        //button3
        else if ((y>=27) && (y<=111) && (x>=5) && (x<=117)){
          page = 6;
          box();
          stsb3();
        }

        //button4
        else if ((y>=27) && (y<=111) && (x>=5) && (x<=117)){
          page = 7;
          box();
          stsb4();
        }

        //button5
        else if ((y>=27) && (y<=111) && (x>=5) && (x<=117)){
          page = 8;
          box();
          stsb5();
        }

        //button6 122, 205, 234, 289
        else if ((y>=205) && (y<=289) && (x>=122) && (x<=234)){
          page = 9;
           box();
          stsb6();
        }
      }

      if (page != 0){

        //Return to main screen button used on all screens
        if ((y>=0) && (y<=239) && (x>=0) && (x<=22)){
          page = 0;
          box();
          mainscr();
          
        }
        else if (page == 0){
          myGLCD.setColor(255, 255, 255);
          myGLCD.setBackColor(255, 0, 0);
          myGLCD.drawRoundRect (0, 26, 239, 0);
          myGLCD.fillRoundRect (0, 26, 239, 0);
          delay (4000);
         // statusbar1();
        }
      }
    }
  }
}

Any help would be appreciated

Your touch() routine is blocking - get rid of the top-level while loop so it'll be non-blocking.

Your touch() routine is blocking

It's more than blocking. No action ever causes the function to end. As MarkT says, you need to rethink how this function is designed/used.

Thanks Mark that works

@PaulS - i'm open to suggestion, i'm still learning, so my code may not be the best, but thats only way i could get my menu to work, so any suggestion to improve my code and my understanding would be appreciated

i'm open to suggestion

Oh, good. Post ALL of your code. The code you posted does not actually call the touch() function. So, it's impossible to tell you what changes you need to make.

But, dealing with the menu AND showing battery status on the same device at the same time are mutually exclusive goals, unless getting the battery status happens in that endless loop function.

@PaulS - see attached, thanks for offering to help me improve my code, on another note, how come my code appears as four files (as attached) in the code folder, have i used the tabs incorrectly? Is there a better way?

Bikeduino_v1.ino (4.69 KB)

drawpage.ino (5.93 KB)

touch.ino (2.34 KB)

gps.ino (6.29 KB)

how come my code appears as four files (as attached) in the code folder, have i used the tabs incorrectly?

No. Each tab refers to a new file. You are using the IDE properly, and quite well.

Why are the status bars drawn using code in the Bikeduino.ino file, instead of in a function in the drawpage.ino file?

The loop() function looks like this:

void loop()
{
  getbattstatus();
  gpsloop();
  touch();
}

Since touch() never returns, the other two functions never get called again.

Since loop() gets called over and over, in an infinite loop, you should simply remove the infinite loop from touch(). It will be called again soon enough.

No. Each tab refers to a new file. You are using the IDE properly, and quite well.

Ok, thanks

Why are the status bars drawn using code in the Bikeduino.ino file, instead of in a function in the drawpage.ino file?

It was something i did while trying to figure out what was stopping the voltage code from working, quite clearly wasn't that and just didn't change it back to using the drawpage.ino, have change it know

you should simply remove the infinite loop from touch()

not sure i follow and how to go about it

not sure i follow and how to go about it

The infinite loop in touch() is:

while(true)
{

at the beginning of the function, and, at the end of the function

}

Highlight the pair of lines at the top, and press delete. Highlight the one at the bottom and press delete.

thanks for your help, i had already removed that piece of code when i posted all my code earlier, which is why couldn't follow your last post