#include <string.h>
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "lwip/err.h"
#include "lwip/sys.h"
#include <LiquidCrystal.h>
#include <WiFi.h>
// #include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ElegantOTA.h>
LiquidCrystal lcd(21,19,18,5,4,2);
#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0;
#else
static const BaseType_t app_cpu = 1;
#endif
int led_pin = LED_BUILTIN;
unsigned long int lastDebounceTime = 0;
unsigned long int debounceDelay = 50;
bool buttonState = false;
void toggleLED(void *parameter) {
while(1) {
digitalWrite(led_pin, HIGH);
vTaskDelay(500 / portTICK_PERIOD_MS);
digitalWrite(led_pin, LOW);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
void LCD(void *parameter) {
while(1) {
lcd.setCursor(0,1);
lcd.noBlink();
vTaskDelay(3000 / portTICK_PERIOD_MS);
lcd.blink();
vTaskDelay(3000 / portTICK_PERIOD_MS);
// lcd.print(millis()/1000);
// delay(2000);
// lcd.clear();
// delay(100);
// lcd.print("Welcome to LPU");
// delay(2000);
// lcd.clear();
// delay(100);
// lcd.print("Chandra Shekhar");
// delay(2000);
// lcd.clear();
// delay(100);
for(int thisChar=0; thisChar<10; thisChar++)
{
lcd.print(thisChar);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
lcd.setCursor(20,1);
lcd.autoscroll();
for(int thisChar=0; thisChar<10; thisChar++)
{
lcd.print(thisChar);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
lcd.noAutoscroll();
lcd.clear();
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
struct Button {
const uint8_t PIN;
uint32_t numberKeyPresses;
bool pressed;
};
Button button1 = {25, 0, false};
void IRAM_ATTR isr() {
button1.numberKeyPresses++;
button1.pressed = true;
}
void setup() {
lcd.begin(20,4);
lcd.print("Hello World!!!");
pinMode(led_pin, OUTPUT);
Serial.begin(115200);
pinMode(button1.PIN, INPUT_PULLUP);
attachInterrupt(button1.PIN, isr, FALLING);
// Task to run forever
xTaskCreatePinnedToCore( // Use xTaskCreate() in vanilla FreeRTOS
toggleLED, // Function to be called
"Toggle LED", // Name of task
2048, // Stack size (bytes in ESP32, words in FreeRTOS)
NULL, // Parameter to pass to function
1, // Task priority (0 to configMAX_PRIORITIES - 1)
NULL, // Task handle
app_cpu); // Run on one core for demo purposes (ESP32 only)
pinMode(led_pin, OUTPUT);
// Task to run forever
xTaskCreatePinnedToCore( // Use xTaskCreate() in vanilla FreeRTOS
LCD, // Function to be called
"LCD", // Name of task
3072, // Stack size (bytes in ESP32, words in FreeRTOS)
NULL, // Parameter to pass to function
1, // Task priority (0 to configMAX_PRIORITIES - 1)
NULL, // Task handle
app_cpu); // Run on one core for demo purposes (ESP32 only)
lastDebounceTime = millis();
}
void loop() {
if (button1.pressed == true) {
if (millis() - lastDebounceTime > debounceDelay) {
lastDebounceTime = millis();
// button1.numberKeyPresses;
// button1.pressed = true;
// Serial.println("Button has been pressed %u times\n", button1.numberKeyPresses);
Serial.println("Button has been pressed \n");
Serial.println(button1.numberKeyPresses);
button1.pressed = false;
}
}
}