Code For Touch Counts and Graded Touch
Code For Touch Counts and Graded Touch
h>
#include <ESP8266WebServer.h>
#include <TM1637Display.h>
#include <ESP8266mDNS.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
// Wi-Fi Credentials
ESP8266WebServer server(80);
// NTP setup
WiFiUDP udp;
NTPClient timeClient(udp, "pool.ntp.org", 18000, 3600000); // UTC+5 for Lahore (18000 seconds)
String getCurrentDate() {
// Get the current date and time from the NTP server
String getCurrentDateTime() {
timeClient.update();
String getHTMLPage() {
html += "<style>body { font-family: Arial; text-align: center; margin: 0; padding: 20px; background-color:
#f4f4f4; }";
html += ".container { position: relative; z-index: 1; padding-bottom: 60px; }"; // Padding to avoid
overlapping branding
html += "</style>";
html += "</div>";
html += "</div>";
html += "</body></html>";
return html;
}
void updateDisplay() {
void setup() {
Serial.begin(115200);
display.setBrightness(7);
display.clear();
display.showNumberDec(counter, false);
pinMode(BUTTON_INCREMENT, INPUT_PULLUP);
pinMode(BUTTON_DECREMENT, INPUT_PULLUP);
pinMode(BUTTON_RESET, INPUT_PULLUP);
WiFi.begin(ssid, password);
Serial.println("Connected to Wi-Fi");
MDNS.begin("esp8266-counter");
timeClient.begin();
server.on("/getCounter", []() {
});
if (server.hasArg("value")) {
counter = server.arg("value").toInt();
updateDisplay();
});
server.begin();
void loop() {
server.handleClient();
lastIncrementState = incrementState;
updateDisplay();
lastDecrementState = decrementState;
counter = 0;
updateDisplay();
lastResetState = resetState;