/*
Simple "Hello World" for ILI9341 LCD
https://wokwi.com/arduino/projects/308024602434470466
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <EEPROM.h>
#define PIN_TASTER_2 2
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
//int interval = 5; //Counter refresh and save interval
int wh_start, wh_total;
int pulseCount, crontimer;
void setup() {
tft.begin();
tft.setCursor(26, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Hello, TFT!");
tft.setCursor(0, 0);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
//tft.println("I can has colors?");
pinMode(PIN_TASTER_2, INPUT_PULLUP);
// Meme reference: https://english.stackexchange.com/questions/20356/origin-of-i-can-haz
}
void loop() {
int zustandTaster = digitalRead(PIN_TASTER_2);
if (zustandTaster == LOW) {
tft.fillScreen(ILI9341_BLACK);
//crontimer = millis() / 1000;
wh_total++;
//save_counter(0, wh_total);
//pulseCount = 0;
//tft.print("Start Wh: ");
// tft.println(wh_start);
tft.setCursor(26, 0);
tft.print("Total Wh: ");
tft.println(wh_total);
tft.println("================");
delay(1000);
}
}
int read_counter(int address)
{
long byte_2 = EEPROM.read(address);
long byte_1 = EEPROM.read(address + 1);
return ((byte_2 << 0) & 0xFFFFFF) + ((byte_1 << 8) & 0xFFFFFFFF);
}
void save_counter(int address, int value)
{
byte byte_2 = (value & 0xFF);
byte byte_1 = ((value >> 8) & 0xFF);
EEPROM.update(address, byte_2);
EEPROM.update(address + 1, byte_1);
}
void onPulse()
{
pulseCount++;
wh_start++;
}