Hi, Here is the whole.
The code compiled without errors before but now it has errors.
Code: Select all
/*
Added line 14-23
Changed and added line 264 and 279
Led Yellow(LED_Y) is working
Need to fix Alarm_LED_Y to work
2022-01-13
*/
#include "SPI.h"
//#include <Wire.h>
#include <esp_now.h>
#include <WiFi.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
//#include <Adafruit_SSD1306.h>
//#include <Arduino_GFX_Library.h>
#define TFT_SCK 18 //14
#define TFT_MOSI 23 //4
#define TFT_MISO 19 //2
#define TFT_CS 5 //12
#define TFT_DC 16 //2,13
#define TFT_RST 17 //4,16
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCK, TFT_RST, TFT_MISO);
///////////////////////////////////SH1106 display////////////////////////////
//Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire);
//#include <Adafruit_SH110X.h>
/* Uncomment the initialize the I2C address , uncomment only one, If you get a totally blank screen try the other*/
//#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's
//#define i2c_Address 0x3d //initialize with the I2C addr 0x3D Typically Adafruit OLED's
//#define SCREEN_WIDTH 128 // OLED display width, in pixels
//#define SCREEN_HEIGHT 64 // OLED display height, in pixels
//#define OLED_RESET -1 // QT-PY / XIAO
//Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
////////////////////////////////////SH1105 display//////////////////////////
//uint8_t broadcastAddress[] = {0xac,0x67,0xb2,0xcc,0xb3,0x00};
uint8_t broadcastAddress[] = {0x7C, 0x9E, 0xBD, 0xF9, 0xB7, 0xB0}; //Receivers address
//#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex
#define PWR_ON 33 //22
#define PSU_ON 25 //32
#define StartStop 36 //BTN
#define _45min 39 //BTN
#define _1h15 34 //BTN
#define LED_R 26 //27
#define LED_G 27 //14,19
#define LED_Y 14 //12,23
#define IRQ 15 //BTN
#define buzzer 13 //26
#define Alarm_LED_Y 12 //13,20
#define TFT_POWER 35 //25 TFT_LED
RTC_DATA_ATTR int bootCount = 0;
int i, j, x, t = 1, k;
uint8_t data = 0;
bool isPaired;
bool a, f, psu;
long psu_time, work_time;
String success;
void Adafruit_ILI9341::sleep(bool value)
{
if (value)
{
writeCommand(0x10); // Send command to put the display to sleep.
delay(5); // Delay for shutdown time before another command can be sent.
}
else
{
writeCommand(0x11); // Send command to wakeup the display.
delay(120); // Wait for the display power supplies to stabilise.
}
}
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
Serial.print("\r\nLast Packet Send Status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
if (status ==0){
success = "Delivery Success :)";
}
else{
success = "Delivery Fail :(";
}
}
// Callback when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
Serial.println(*incomingData);
if(*incomingData == 5){
t = 0;
digitalWrite(buzzer,HIGH);
digitalWrite(Alarm_LED_Y,HIGH);
delay(2000);
digitalWrite(buzzer,LOW);
delay(8000);
digitalWrite(Alarm_LED_Y,LOW);
}
if(*incomingData == 9){
psu = 1;
psu_time = millis();
}
}
void setup(){
Serial.begin(115200);
pinMode(PWR_ON,OUTPUT);
pinMode(PSU_ON,OUTPUT);
digitalWrite(PWR_ON,LOW);
digitalWrite(PSU_ON,LOW);
pinMode(_45min,INPUT);
digitalWrite(_45min,HIGH);
pinMode(StartStop,INPUT);
digitalWrite(StartStop,HIGH);
pinMode(_1h15,INPUT);
digitalWrite(_1h15,HIGH);
pinMode(LED_R,OUTPUT);
digitalWrite(LED_R,LOW);
pinMode(LED_G,OUTPUT);
digitalWrite(LED_G,LOW);
pinMode(LED_Y,OUTPUT);
digitalWrite(LED_Y,LOW);
pinMode(Alarm_LED_Y,OUTPUT);
digitalWrite(Alarm_LED_Y,LOW);
pinMode(buzzer,OUTPUT);
pinMode(TFT_POWER,OUTPUT);
++bootCount;
Serial.println("Boot number: " + String(bootCount));
//Print the wakeup reason for ESP32
//print_wakeup_reason();
if(bootCount == 1){
esp_sleep_enable_ext0_wakeup(GPIO_NUM_15,1);
//Go to sleep now
Serial.println("Going to sleep now");
delay(1000);
esp_deep_sleep_start();
Serial.println("never shows this massage");
}
digitalWrite(PWR_ON,HIGH);
WiFi.mode(WIFI_STA);
// Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for Send CB to
// get the status of Trasnmitted packet
esp_now_register_send_cb(OnDataSent);
// Register peer
esp_now_peer_info_t peerInfo = {};
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
// Add peer
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
f = 0;
return;
}else{
f = 1;
}
Serial.println(f);
// Register for a callback function that will be called when data is received
esp_now_register_recv_cb(OnDataRecv);
// Arduino_ESP32SPI bus = Arduino_ESP32SPI(TFT_DC, TFT_CS, TFT_SCK, TFT_MOSI, TFT_MISO);
// Arduino_ILI9341 tft = Arduino_ILI9341(&bus, TFT_RESET);
digitalWrite(TFT_POWER, HIGH); // turn on backlight
//digitalWrite(TFT_RST, HIGH); // set RS LOW
tft.sleep(false);
delay(200);
gpio_hold_dis((gpio_num_t) TFT_RST);
gpio_deep_sleep_hold_dis();
tft.begin();
tft.fillScreen(ILI9341_RED);
yield();
tft.fillScreen(ILI9341_BLACK);
yield();
tft.setRotation(1);
tft.setCursor(5, 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(4);
tft.println("DishWasher \nTimer\n by\nNagatronic AB");
//display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
//display.begin(i2c_Address, true); // Address 0x3C default for SH1106 display
//Serial.println("OLED begun");
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
//display.display();
delay(3000);
tft.fillScreen(ILI9341_BLACK);
yield();
tft.setCursor(5, 5);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.print("TIMER:OFF"); tft.setCursor(5, 30);
tft.print("Press IRQ button to wakeup\nPress chosen TIME\nand START buttons\nto start timer");
// Clear the buffer.
// display.clearDisplay();
// display.display();
// display.setCursor(0,10);
// //display.setTextColor(SSD1306_WHITE);
// display.setTextColor(SH110X_WHITE); // For SH1106 display
// display.setTextSize(1);
// display.print("\tTIMER:OFF\nPress chosen TIME andSTART buttons to \nstart timer");
// display.display();
work_time = millis();
}
void loop(){
digitalWrite(LED_G,LOW);
digitalWrite(LED_R,LOW);
digitalWrite(LED_Y,LOW);
if(millis()-psu_time >= 6000){
psu = 0;
}
if(psu){
digitalWrite(PSU_ON,HIGH);
}else{
digitalWrite(PSU_ON,LOW);
}
//int v = 1;
if(digitalRead(_45min) == 0 && psu == 1){
//if(v){
digitalWrite(LED_G,HIGH);
i = 46;
k = 0;
while(i>=0){
if(f){
//if(v){
if(digitalRead(StartStop) == 0 || a == 1){
//if(v){
if(i>=46 && k>=59){
digitalWrite(buzzer,HIGH);
}else{
digitalWrite(buzzer,LOW);
}
a = 1;
Serial.println(" timer1:on ");
digitalWrite(LED_R,HIGH);
//delay(800);
if(i == 46){
tft.setCursor(30, 30);
tft.fillScreen(ILI9341_BLACK);
tft.print("TIMER:ON 45 min");
tft.setCursor(110, 80);
tft.print("00:45");
x = 1;
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &x, sizeof(int));
if (result == ESP_OK) {
Serial.println("Sent with success");
}
else {
Serial.println("Error sending the data");
}
}
if(digitalRead(StartStop) == 0 || t == 0){
//if(!v){
t = 1;
a = 0;
Serial.println(" timer1:off ");
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(5, 5);
tft.print("TIMER:OFF"); tft.setCursor(5, 30);
tft.print("Press IRQ button to wakeup\nPress chosen TIME\nand START buttons\nto start timer");
// display.clearDisplay();
// display.setCursor(0,10);
// display.print("\tTIMER:OFF\nPress chosen TIME andSTART buttons to \nstart timer");
// display.display();
x = 3;
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &x, sizeof(int));
if (result == ESP_OK) {
Serial.println("Sent with success");
}
else {
Serial.println("Error sending the data");
}
digitalWrite(buzzer,HIGH);
delay(1000);
digitalWrite(buzzer,LOW);
break;
}
// display.clearDisplay();
// display.setCursor(0,0);
// display.print("TIMER:ON 45min");
// display.setCursor(6,20);
// display.print("00:");
k--;
if(k<=0){
i--;
if(i == 0){
k = 1;
}else{
k = 59;
}
tft.fillRect(110, 80, 100, 60, ILI9341_BLACK);
tft.setCursor(110, 80);
tft.print("00:");
if(i<10){
tft.print("0");
tft.print(i);
}else{
tft.print(i);
}
delay(500);
}else{
delay(1000);
}
}
}
if(millis()-psu_time >= 5000){
psu = 0;
}
if(psu){
digitalWrite(PSU_ON,HIGH);
}else{
digitalWrite(PSU_ON,LOW);
}
}
digitalWrite(buzzer,HIGH);
delay(1000);
digitalWrite(buzzer,LOW);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(5, 5);
tft.print("TIMER:OFF"); tft.setCursor(5, 30);
tft.print("Press IRQ button to wakeup\nPress chosen TIME\nand START buttons\nto start timer");
// display.clearDisplay();
// display.setCursor(0,10);
// display.print("\tTIMER:OFF\nPress chosen TIME andSTART buttons to \nstart timer");
// display.display();
work_time = millis();
}
a = 0;
if(digitalRead(_1h15) == 0 && psu == 1){
digitalWrite(LED_Y,HIGH);
i = 16;
j = 1;
k = 0;
while(j>=0){
if(f){
if(digitalRead(StartStop) == 0 || a == 1){
if(i>=16 && k>=59 && j==1){
digitalWrite(buzzer,HIGH);
}else{
digitalWrite(buzzer,LOW);
}
a = 1;
Serial.println(" timer2:on ");
digitalWrite(LED_R,HIGH);
//delay(800);
if(i == 16 && j == 1){
tft.setCursor(30, 30);
tft.fillScreen(ILI9341_BLACK);
tft.print("TIMER:ON 1hr 15min");
tft.setCursor(110, 80);
tft.print("01:15");
x = 2;
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &x, sizeof(int));
if (result == ESP_OK) {
Serial.println("Sent with success");
}
else {
Serial.println("Error sending the data");
}
}
if(digitalRead(StartStop) == 0 || t == 0){
t = 1;
a = 0;
Serial.println(" timer2:off ");
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(5, 5);
tft.print("TIMER:OFF"); tft.setCursor(5, 30);
tft.print("Press IRQ button to wakeup\nPress chosen TIME\nand START buttons\nto start timer");
// display.clearDisplay();
// display.setCursor(0,10);
// display.print("\tTIMER:OFF\nPress chosen TIME andSTART buttons to \nstart timer");
// display.display();
x = 4;
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &x, sizeof(int));
if (result == ESP_OK) {
Serial.println("Sent with success");
}
else {
Serial.println("Error sending the data");
}
digitalWrite(buzzer,HIGH);
delay(1000);
digitalWrite(buzzer,LOW);
break;
}
// display.clearDisplay();
// display.setCursor(0,0);
// display.print("TIMER:ON 1hr 15min");
// display.setCursor(6,20);
// display.print("0");
// display.print(j);
// display.print(":");
if(i == 0){
i = 59;
j--;
}
k--;
if(k<=0){
i--;
k = 59;
tft.fillRect(110, 80, 100, 60, ILI9341_BLACK);
tft.setCursor(110, 80);
tft.print("0");
tft.print(j);
tft.print(":");
if(i<10){
tft.print("0");
tft.print(i);
}else{
tft.print(i);
}
delay(500);
}else{
delay(1000);
}
}
}
if(millis()-psu_time >= 5000){
psu = 0;
}
if(psu){
digitalWrite(PSU_ON,HIGH);
}else{
digitalWrite(PSU_ON,LOW);
}
}
digitalWrite(buzzer,HIGH);
delay(800);
digitalWrite(buzzer,LOW);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(5, 5);
tft.print("TIMER:OFF"); tft.setCursor(5, 30);
tft.print("Press IRQ button to wakeup\nPress chosen TIME\nand START buttons\nto start timer");
// display.clearDisplay();
// display.setCursor(0,10);
// display.print("\tTIMER:OFF\nPress chosen TIME andSTART buttons to \nstart timer");
// display.display();
work_time = millis();
}
if(millis()-work_time >= 15000){
digitalWrite(PWR_ON,LOW);
tft.sleep(true);
delay(500);
digitalWrite(TFT_POWER, LOW); // turn off backlight
digitalWrite(TFT_RST, LOW); // set RS LOW
gpio_hold_en((gpio_num_t) TFT_RST); // enable hold for the pin
gpio_deep_sleep_hold_en(); // enable hold in deep sleep
Serial.println("Going to sleep now");
esp_sleep_enable_ext0_wakeup(GPIO_NUM_15,1);
esp_deep_sleep_start();
Serial.println("never shows this massage");
}
}