#include <Arduino.h>
#include <EEPROM.h>
int lastcount;
const int buttonPin = 2; // GPIO2 is a commonly used pin on the ESP32 for buttons
int counter =0; // Initialize the counter
const int tds =50;
int value =10;
const int steps =1000;
void setup() {
EEPROM.begin(512); //Initialize the EEPROM with a size
pinMode(buttonPin, INPUT_PULLUP); // Set the button pin as input with internal pull-up resistor
Serial.begin(115200); // Initialize serial communication
//Read the last counter form EEPROM
lastcount = EEPROM.read(0);
// Print the initial value of the counter
Serial.print("Counter: ");
Serial.println(counter);
}
void loop() {
// Read the state of the button
int buttonState = digitalRead(buttonPin);
// Check if the button is pressed (LOW)
if (buttonState == LOW) {
// Increment the counter by 1
counter++;
EEPROM.write(0,counter); //Strore the updated count in EEPROM
EEPROM.commit(); // Save change to EEPROM
// Print the updated counter value
Serial.print("TDS SEL : ");
Serial.println(counter);
delay(250); // Delay for debouncing
}
if (counter >=5){
counter = 0;
}
}