#include "User_Setup.h"
#include <SPI.h>
#include <TFT_eSPI.h>
#include "NotoSansBold15.h"
#include "NotoSansBold36.h"
#include "CourierB24.h"
#include "Unicode_Test_72.h"
#include "background.h"
#define SOLENOID_PIN 4
#define BUZZER_PIN 37 // Define your buzzer pin (e.g., GPIO 5)
#define RST 6
#define T5 14
#define T10 12
#define T15 10
#define PLUS1 8
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite spr = TFT_eSprite(&tft);
TFT_eSprite sprT = TFT_eSprite(&tft);
int oldV = -1;
int v;
float vf1;
unsigned long tNow;
unsigned long tRead;
unsigned int timeout = 0;
byte minutes, seconds;
unsigned long debounce;
// State tracking for the buzzer
bool lastSolenoidState = false;
void setup() {
Serial.begin(115200);
pinMode(SOLENOID_PIN, OUTPUT);
digitalWrite(SOLENOID_PIN, LOW);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
pinMode(RST, INPUT_PULLUP);
pinMode(T5, INPUT_PULLUP);
pinMode(T10, INPUT_PULLUP);
pinMode(T15, INPUT_PULLUP);
pinMode(PLUS1, INPUT_PULLUP);
tft.begin();
tft.setRotation(3);
tft.setSwapBytes(true);
tft.pushImage(0, 0, 320, 240, (uint16_t *)image1);
spr.loadFont(NotoSansBold36);
spr.setTextColor(TFT_WHITE, TFT_BLACK);
spr.createSprite(200, 36);
sprT.loadFont(CourierB24);
sprT.setTextColor(TFT_YELLOW, TFT_BLACK);
sprT.createSprite(180, 24);
tNow = millis();
tRead = millis();
}
// Helper function for a quick beep
void beep(int duration) {
//digitalWrite(BUZZER_PIN, HIGH);
tone(BUZZER_PIN, 500);
delay(duration);
noTone(BUZZER_PIN);
//delay(duration);
//digitalWrite(BUZZER_PIN, LOW);
}
void loop() {
// --- Button Handling ---
if(millis() - debounce > 250){
if (digitalRead(T5) == LOW) { timeout = 300; debounce = millis(); }
if (digitalRead(T10) == LOW) { timeout = 600; debounce = millis(); }
if (digitalRead(T15) == LOW) { timeout = 900; debounce = millis(); }
if (digitalRead(PLUS1) == LOW) { timeout += 60; debounce = millis(); }
if (digitalRead(RST) == LOW) { timeout = 0; debounce = millis(); }
}
// --- Solenoid & Buzzer Logic ---
bool currentSolenoidState = (timeout > 0);
if (currentSolenoidState != lastSolenoidState) {
if (currentSolenoidState) {
// Logic: Started (0 -> 1)
digitalWrite(SOLENOID_PIN, HIGH);
beep(150); // Single short beep for start
} else {
// Logic: Ended (1 -> 0)
digitalWrite(SOLENOID_PIN, LOW);
beep(500); // Longer beep or double beep for end
delay(100);
beep(500);
}
lastSolenoidState = currentSolenoidState;
}
// --- Timer Update (Every 1 Second) ---
if (millis() - tNow >= 1000) {
tNow = millis();
if (timeout > 0) timeout--;
sprT.fillSprite(TFT_BLACK);
sprT.setCursor(0, 0);
minutes = timeout / 60;
seconds = timeout % 60;
if (minutes < 10) sprT.print("0");
sprT.print(minutes);
sprT.print(":");
if (seconds < 10) sprT.print("0");
sprT.print(seconds);
sprT.pushSprite(200, 45);
}
// --- CO2 Sensor Update (Every 500ms) ---
if (millis() - tRead >= 500) {
tRead = millis();
v = analogRead(3);
if (abs(oldV - v) > 5) {
vf1 = v / 81.92;
oldV = v;
spr.fillSprite(TFT_BLACK);
spr.setCursor(0, 0);
spr.print(vf1, 1);
spr.print("%");
spr.pushSprite(100, 80);
}
}
}Loading
wemos-s2-mini
wemos-s2-mini
Loading
ili9341-cap-touch
ili9341-cap-touch