For some reason Hz, previousHz and currentHz are the same ?
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>
#define TFT_MOSI 23 // Data out
#define TFT_SCLK 18 // Clock out
#define TFT_CS 22//
#define TFT_DC 21 //
#define TFT_RST -1 // pin# 2
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
int Hz;
int currentHz;
int previousHz = 0;
void setup()
{
Serial.begin(115200);
tft.init(170, 320); // high, with
tft.setRotation(3); // Adjust rotation as needed (0-3),0 = viertical, 1= horyzontal upside down, 2= viertical 180 deg , 3=horyzontal normal,
tft.fillScreen(ST77XX_BLUE);
tft.setTextWrap(false); // Disable text wrapping
tft.setTextSize(4); // Set text size
pinMode(12, INPUT_PULLUP); //amp ++
pinMode(14, INPUT_PULLUP); // amp --
pinMode(2, INPUT_PULLUP);
}
void loop() {
// int Hz;
if (digitalRead(12) == LOW)
{
Hz++;
}
if (digitalRead(14) == LOW)
{
Hz--;
}
currentHz = Hz;
previousHz = currentHz;
//if ( previousHz != Hz) // re-writing the old data in background color
if (currentHz != previousHz)
//if ( previousHz != currentHz )
{
tft.setCursor(0, 0);
tft.setTextColor(ST77XX_BLUE); // background color
tft.print( previousHz);
// tft.print( currentHz);
tft.setTextColor(ST77XX_YELLOW);
tft.print("Hz = ");
tft.print( Hz);
//tft.println( currentHz);
}
// previousHz = currentHz;
/*
///////////////////////
tft.setTextColor(ST77XX_YELLOW);
if (currentHz != previousHz)
{
tft.setCursor(30, 0);
tft.fillRect(29, 0, 30, 10, ST77XX_BLUE); //depends on the hight of the font and how long the static text is
tft.setTextColor(ST77XX_YELLOW);
tft.print(Hz);
}
///////////////////
*/
Serial.print(" prev = "); Serial.print(previousHz);
Serial.print(" cur = "); Serial.print(currentHz);
Serial.print(" Hz = "); Serial.print(Hz);
Serial.println();
delay(100);
}