/*Me:a haghighat panah test PRO
----------
♦ME: symbol meaning:♦{
☻ : "No need this seems extra"
}
*/
/*************************************************************
This is a simple demo of sending and receiving some data.
Be sure to check out other examples!
*************************************************************/
//==================[HEADER FILES]==================V
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <WiFiClient.h>
// -------[blynk]---------V
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL4Zyq3HNsV"
#define BLYNK_TEMPLATE_NAME "AHP BLYNK TEMPLATE"
#define BLYNK_AUTH_TOKEN "cUiNrA0de1qBFz5nVOOtcPwyADfKyThh"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp32.h>
// #include <Servo.h>
//==================[PIN DEFINE]==================V
#define GREEN_LCD_PIN 23
#define BLUE_LCD_PIN 34
#define POTENTIOMETER_PIN 33
#define PUSH_BUTTON 32
//==================[Objects]==================V
LiquidCrystal_I2C Green_LCD = LiquidCrystal_I2C(0x26, 16, 2);
LiquidCrystal_I2C Blue_LCD = LiquidCrystal_I2C(0x27, 16, 2);
BlynkTimer timer;
//==================[Golbal variable]==================V
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// Variables to caliberate the soil Moisture sensor
const int dryValue = 590; //you need to replace this value with Value_1
const int wetValue = 300; //you need to replace this value with Value_2
int soil_moistValue; // The analogue reading of the sensor
int soil_moistPercent;
const int moistThreshold = 60; // Water pump is activated ones soil moisture falls bellow this level
bool soil_isDry = false;
String myStatus = "";
unsigned int button_count = 0;
// int LCD_view = 0;
float lcd_state = 0;
float temp = 0;
int Plant_mode = 0;
//===========================[BLYNK : READ | WRITE | Functions]===========================V
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0) // Me: az site (Blynk) dade dar (ESP32) neveshte (write) mish
{
// Set incoming value from pin V0 to a variable
int value = param.asInt(); // assigning incoming value from pin V1 to a variable
// String i = param.asStr();
// double d = param.asDouble()
// Update state
Blynk.virtualWrite(V1, value); // Me: meghdare [value] be vritual pin (V1) dade mishe
Serial.println("blynk swicth: " + String(value));
//Me: etefaghi ke dare in ja moyofet in hast ke az blynk dare ,.......... {EDAM TOZIE BADAN MINVISAM}
}
BLYNK_WRITE(V4) //Me: plant silder get data
{
Plant_mode = param.asInt();
// Serial.println("Plant: " + String(value));
}
BLYNK_WRITE(V5) //Me: plant swicth button get data
{
test2_Blynk_plant (param.asInt());
}
// This function is called every time the device is connected to the Blynk.Cloud
// Me: dastortar khodemon ro dar in ghsmate migozriam ta bad az in key (MUC : ESP32) be (Blynk) mostal shode ejra beshe
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
/* Me:☻
Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
*/
}
// /* Me: eyk tabe karvorid dige
// BLYNK_READ(V5) // Widget in the app READs Virtal Pin V5 with the certain frequency
// {
// // This command writes Arduino's uptime in seconds to Virtual Pin V5
// Blynk.virtualWrite(5, millis() / 1000);
// }
// */
// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V2, millis() / 1000);
}
//===========================[BLYNK : READ | WRITE | Functions]===========================V
//===============[MY FUNCTIONS]===============v
void test1_pote () {
temp = analogRead(POTENTIOMETER_PIN);
//Me: replacment for LCD,clear function lag for not having delay-------------V
// Blue_LCD.clear();
// Blue_LCD.print("value: ");
if (lcd_state != temp) Blue_LCD.clear();
lcd_state = temp; // Me: {temp} va {lcd_state} = (Global vars) hastand
Blue_LCD.setCursor(0, 0);
//Me: replacment for LCD.clear function lag for not having delay-------------^
Blue_LCD.print("value:" + String(temp));
Blynk.virtualWrite(V6, temp);
// if (button ()) {
// Serial.println("sending : " + String(temp));
// }
}
void test2_Blynk_plant(int plant_mode_button) {
if (plant_mode_button == 1) Serial.println("sending : " + String(Plant_mode));
}
/*a
void blynk_button () {
int t_array[] = {0, 1, 2, 3};
if (digitalRead(PUSH_BUTTON) == LOW) {
Blynk = t_array[button_count];
button_count++;
// Serial.println(dcount);
// delay(100);
// delay(100);
if (button_count >= 4 ) button_count = 0;
}
*/
boolean button () {
if (digitalRead(PUSH_BUTTON) == LOW) return true;
else return false;
}
//^===============^[MY FUNCTIONS]^===============^
//V==============V[♦ MAIN PORGRAM ♦}V==============V
void setup()
{
Serial.begin(115200); // baud rate
//---------------[Pin mode config]---------------
pinMode(PUSH_BUTTON, INPUT_PULLUP);
// pinMode(POTENTIOMETER_PIN, INPUT);
//---------------[LCD config]---------------
Green_LCD.init();
Green_LCD.backlight();
Green_LCD.clear();
Green_LCD.setCursor(0, 0);
Green_LCD.print("test pro");
Blue_LCD.init();
Blue_LCD.backlight();
Blue_LCD.clear();
Blue_LCD.setCursor(0, 0);
Blue_LCD.print("Haghighat panah");
//---------------[wi if connect]---------------
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
//---------------[blynk]---------------
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // turn on
// You can also specify server:
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent); // turn on
}
void loop()
{
Blynk.run();
timer.run();
test1_pote();
}