Pages: [1]   Go Down
Author Topic: integrating voltage ref code (or other variables) into touch screen code  (Read 1052 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.InitLCD(PORTRAIT);
  myGLCD.clrScr();
  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.setFont(BigFont);
  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.setFont(BigFont);
  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

* ITDB02_Touch_ButtonTest_hacked2.ino (10.1 KB - downloaded 12 times.)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: