I have used a Graphing to LCD program and have been modifying it to suit my application (which is very simple)
I need to read a value from an analog pin every 200mSec and display the point on a graph.
Set an Alarm level line on the graph and trigger a relay if it exceeds the Alarm level.
Print the weight at the bottom of the screen that the sensor is reading.
The weigh at the bottom of the screen is where I am having a problem. It only prints the value if I push on the screen somewhere and each time I touch the screen the value will update. I am trying to print the weight continuously.
I have moved that part of the code to several different places expecting it would be outside a conditional loop somewhere, but always the same result. I don't understand enough where the program is sitting to wait for some input. I thought the IF statements would just check if the condition was TRUE, and if the program continues to execute.
Any help as to what I am misunderstanding would be greatly appreciated.
void loop () {
//Read Value from Strain Gauge and send
//it to Tension Function then return calculated weight.
sensor1Val = analogRead(sensor1Pin);
Kg = Tension(sensor1Val);
TSPoint p = ts.getPoint();
if (p.z > ts.pressureThreshhold) {
//get point on touchscreen that has been touched
pinMode(YP, OUTPUT); //.kbv these pins are shared with TFT
pinMode(XM, OUTPUT); //.kbv these pins are shared with TFT
tft.fillRect(100, Kg, 1, 2, YELLOW);
tft.setCursor(220, 210);
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
if (p.z > ts.pressureThreshhold) {
//Determine if the "INC" alarm button is pressed and draw
//new Alarm line
if (p.x > 794 && p.x < 872 && p.y > 138 && p.y < 265) {
tft.drawLine(50, Alarm, 315, Alarm, BLACK);
Alarm = Alarm + 10 ;
if (Alarm > 200) Alarm = 200;
tft.drawLine(50, Alarm, 315, Alarm, RED);
}
//Determine if the "DEC" alarm level is pressed and draw
//new alarm line
if (p.x > 811 && p.x < 879 && p.y > 295 && p.y < 414) {
tft.drawLine(50, Alarm, 315, Alarm, BLACK);
Alarm = Alarm - 10 ;
if (Alarm < 0) Alarm = 0;
tft.drawLine(50, Alarm, 315, Alarm, RED);
//Serial.println (Alarm);
//Serial.println(p.x); Serial.println(p.y);
}
//Print the Alarm Level Value on the side that corresponds with the
//Alarm Level line.
AlarmLevel = 400 - (Alarm * 2);
tft.fillRect(1, 0, 43, 203, BLACK);
tft.setCursor(5, Alarm);
tft.setTextColor(BLUE);
tft.setTextSize(2);
tft.print(AlarmLevel);
}
delay(300);
}
// Print the Weight Value and Kg at the bottom left of screen.
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.setCursor(280, 210);
tft.print("Kg");
tft.setCursor(220, 210);
tft.fillRect(220, 210, 54, 22, BLACK);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.print(Kg);
}
int Tension(int Weight) {
Weight = sensor1Val / 3;
return Weight;
}