Im new to programming and im sure this is easy for someone with a little experience, but i just cant work out how to do it.
When the arduino takes the reading from the potentiometer it maps it from 0 - 100 and displays it on the TFT LCD screen. If the reading goes up to 100 and back down the last 0 remains on the screen, making all the numbers look like they are 10x bigger (eg 990, 980 etc) . I can get round this by painting the numbers black before the update but this causes the numbers to flicker
How do i track the potentiometer value so the display only updates if it changes.I have found plenty of material on tracking a digital input but not on analogue. What i have done so far just isnt working for me so i have posted the code with what i have working.
Thanks in advance
#include <UTFT.h>
// Declare which fonts we will be using
extern uint8_t SevenSegNumFont[];
UTFT myGLCD(ITDB50,38,39,40,41); // Remember to change the model parameter to suit your display module!
//UTouch myTouch(6,5,4,3,2);
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
int lastoutputValue = 0;
void setup()
{
Serial.begin(9600);
// Setup the LCD
myGLCD.InitLCD();
myGLCD.clrScr();
}
void loop()
{
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 100);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
Serial.print("\t lastoutputvalue = ");
Serial.println(lastoutputValue);
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
if (outputValue != lastoutputValue);
{
myGLCD.setColor(0, 0, 0);
myGLCD.fillRoundRect (5, 5, 150, 53);
myGLCD.setColor(0, 255, 255);
myGLCD.setFont(SevenSegNumFont);
myGLCD.printNumI(int(outputValue), 5, 5);
int lastoutputValue = outputValue;
}
}