/*
Arduino | coding-help
Screen Flicker when updating values
Syn [puffy], puffy - Tuesday, May 5, 2026 5:26 PM
Trying to make a custom digital boost/vacuum gauge with a map sensor.
I finally got the values to be stable but it's causing my SPI screen to flicker.
Based on:
https://wokwi.com/projects/307567201804616256
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
const int TFT_DC = 9;
const int TFT_CS = 10;
const int SENSOR_PIN = A0;
int val = 0;
int oldValue = -1; // just so it is never the "raw value" on startup
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
Serial.begin(9600);
Serial.println("ILI9341 Test!");
tft.begin();
tft.setTextSize(3);
tft.setTextColor(ILI9341_GREEN, ILI9341_BLACK);
}
void loop(void) {
val = analogRead(SENSOR_PIN); // read the input pin
Serial.println(val); // debug value
tft.setCursor(70, 50);
val= map(val, 0, 1023, -30, 20);
//if (val > 484){
//val = map(val, 485, 1023, 0, 20);
//val = constrain(val, 0, 20);
//}
//else if (val < 484){
//val = map(val, 0, 483, -30, 0);
//al = constrain(val, -30, 0);
//}
//else (val = 0);
tft.print(val);
delay(50);
//tft.setTextColor(ST77XX_BLACK, ST77XX_BLACK);
tft.setCursor(70, 50);
tft.print(val); // this stopped number freakout
//tft.fillScreen(ST77XX_BLACK);
// Y = MX+B x is val m would be the co eff that turns val into PSI B is 485
}