I have a working display, showing vaue 'i', and with 2 buttons, the value goes up and down by 1 with each press. Works great, and shows on the display. The error, is when the amount of digits increase to double digits, and then decreases to single digits, the single digit is in the wrong place, and looks like it is counting down in tens, as the second digit '0' remains.
// EEPROM - Version: Latest
#include <EEPROM.h>
int i = EEPROM.read(1);
#include "Button.h"
//Apples
PushButton button1 = {22};
PushButton button2 = {24};
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// work in line numbers. Font height in ht
int16_t ht = 16, top = 3, line, lines = 15, scroll;
void setup()
{
Serial.begin(9600);
uint16_t id = tft.readID();
tft.begin(id);
tft.setRotation(0); //Portrait
tft.fillScreen(BLACK);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(3); // System font is 8 pixels. ht = 8*2=16
tft.setCursor(85, 10);
tft.print("Count");
tft.setTextSize(4);
tft.setCursor(20, 70);
tft.print("Apples =");
}
void loop()
{
tft.setTextSize(4);
tft.setTextColor(RED, BLACK);
if (button1.isPressed()) {
i = i + 1;
}
if (button2.isPressed()) {
i = i - 1;
}
tft.setCursor(200, 70);
tft.print (i);
}
I found this:
char mystring[10]; // Space for 9 characters + null termination
sprintf(mystring, "%d", 1234);
tft.drawString(mystring, 30, 30, 2, YELLOW);
but the error is: drawstring not defined.
Is somebody able to please enlighten me, thanks.