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