Go Down

Topic: integrating voltage ref code (or other variables) into touch screen code (Read 2318 times) previous topic - next topic


I have been trying to integrate my voltage reference code into my touch screen code, the voltage reading changes when a fresh page is loaded but not if left on one page and pot is adjusted.

See voltage reference below, which when run on its own, the voltage displayed changes with the adjustment of the pot

Code: [Select]

#include <UTFT.h>

extern uint8_t BigFont[];
const int systembattpin = A8; // pin that the sensor is attached to
const int controlbattpin = A9;
float voltage1 = 0;
float voltage2 = 0;

UTFT myGLCD(ITDB32S,38,39,40,41);

int x, y;

void setup()
 // Initial setup
 myGLCD.setBackColor(255, 255, 255);

void loop()
 // read the input on analog pin 8:
 int sensorValue = analogRead(A8);
 // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
 float voltage1 = ((sensorValue * 1.68) * (5.0 / 1023.0));
 myGLCD.setColor(0, 0, 255);
 myGLCD.print("System battery", CENTER, 50);
 myGLCD.printNumF(voltage1, 1, CENTER, 100, '.', 3, ' ');
 // read the input on analog pin 9:
 int sensorValue1 = analogRead(A9);
 // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
 float voltage2 = ((sensorValue * 1.68) * (5.0 / 1023.0));
 myGLCD.setColor(0, 0, 255);
 myGLCD.print("Control battery", CENTER, 150);
 myGLCD.printNumF(voltage2, 1, CENTER, 200, '.', 3, ' ');

So why does this not happen when it is integrated into my main code?
Is it the way i have constructed my menu code?
Do i need function to check whether the voltage has changed and if so update/refresh?

See main code attached, as its too long to post

The voltage reading is calculated in void getbattstatus() which is called by void statusbar2(), is this the wrong way to go about it, any help would be grateful, as this will help with integrating time and date code

Thanks in advance


I started to look at your code. I got to the infinite loop in the loop() function, and quit reading. Seeing as how loop() is called in an endless loop, why do you feel it necessary to prevent that from happening, while you run your own infinite loop?

What I did see suggests to me that you are running out of memory. Making use of the F() macro might help.

  myGLCD.print(F("Control battery"), CENTER, 150);

Use it everywhere you have a constant string.
The art of getting good answers lies in asking good questions.

Go Up