mirror of
https://github.com/Skysamara/hydro.git
synced 2025-12-06 06:16:01 +00:00
Не работает помпа
This commit is contained in:
parent
2bd1c8424b
commit
21f6546f58
@ -1,89 +1,3 @@
|
||||
//////////////////////////////////////////////////////////////
|
||||
class Pump
|
||||
{
|
||||
int pin; // Куда подключен
|
||||
unsigned long lastTime;
|
||||
int duration; // Время полива
|
||||
|
||||
int maxDuration; // Максимальное время полива
|
||||
int currentDuration; // Текущее время полива для отображения в приложении
|
||||
|
||||
public:
|
||||
Pump(int p) // Пин
|
||||
{
|
||||
pin = p;
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, HIGH); // При создании выключена // Инверсия
|
||||
|
||||
lastTime = millis();
|
||||
currentDuration = 0;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if ((millis() - lastTime) > duration * 1000)
|
||||
{
|
||||
digitalWrite(pin, HIGH); // Инверсия
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (!IsON())
|
||||
{
|
||||
Serial.print("Start! ");
|
||||
Serial.println(duration);
|
||||
lastTime = millis();
|
||||
digitalWrite(pin, LOW); // Инверсия
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
void Stop()
|
||||
{
|
||||
if (IsON())
|
||||
{
|
||||
Serial.print("Stop! ");
|
||||
Serial.println(duration);
|
||||
lastTime = millis();
|
||||
digitalWrite(pin, HIGH); // Инверсия
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
boolean IsON() // Текущее состояние
|
||||
{
|
||||
if (digitalRead(pin) == LOW) // Инверсия
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int GetCurrentDuration()
|
||||
{
|
||||
if (IsON()) // Если помпа включена
|
||||
{
|
||||
return ((millis() - lastTime) / 1000); // Текущее время полива
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SetDuration(int d)
|
||||
{
|
||||
duration = d;
|
||||
Serial.print("SetDuration ");
|
||||
Serial.println(duration);
|
||||
}
|
||||
};
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
#define BLYNK_PRINT Serial
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <BlynkSimpleEsp8266.h>
|
||||
@ -91,70 +5,27 @@ class Pump
|
||||
#include "WEMOS_Motor.h"
|
||||
#include <EEPROM.h>
|
||||
|
||||
//char auth[] = "Fdj2ndHfZmRirtgrgdrfh81fzPpfB0-"; // origin
|
||||
//char ssid[] = "WIFI";
|
||||
//char pass[] = "132password";
|
||||
|
||||
#include "auth.h"
|
||||
|
||||
|
||||
BLYNK_CONNECTED() {
|
||||
// Request Blynk server to re-send latest values for all pins
|
||||
Blynk.syncAll();
|
||||
}
|
||||
|
||||
#define DHTTYPE DHT22
|
||||
#define DHTPin 0 //D3 DHT датчик
|
||||
#define term_power 4 //D2
|
||||
//#define term_power 4 //D2
|
||||
#define term_power 16 //D0. D1, D2 заняты моторами
|
||||
#define led_pin 2 // D4
|
||||
//#define pump1_pin 3 // ??????????D4
|
||||
|
||||
boolean led_status = 0;
|
||||
float Temperature;
|
||||
float Humidity;
|
||||
boolean led_status = 0;
|
||||
//float Temperature;
|
||||
//float Humidity;
|
||||
|
||||
DHT dht(DHTPin, DHTTYPE); // Инициализация датчика DHT
|
||||
BlynkTimer timer;
|
||||
DHT dht(DHTPin, DHTTYPE); // Инициализация датчика DHT
|
||||
BlynkTimer timer;
|
||||
|
||||
// Pump pump1(pump1_pin);
|
||||
Pump pump1(led_pin);
|
||||
BLYNK_CONNECTED() {
|
||||
// Request Blynk server to re-send latest values for all pins
|
||||
blynk_connected();
|
||||
}
|
||||
|
||||
Motor M1(0x30,_MOTOR_A, 1000); // Помпа
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// BLYNK_WRITE() на первой вкладке, по-другому не работает //
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
BLYNK_WRITE(V0) // Длительность полива первой помпы
|
||||
{
|
||||
int d = param.asInt();
|
||||
pump1.SetDuration(d);
|
||||
Serial.print("Длительность: ");
|
||||
Serial.println(d);
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V1) // Таймер
|
||||
{
|
||||
// You'll get HIGH/1 at startTime and LOW/0 at stopTime.
|
||||
// this method will be triggered every day
|
||||
// until you remove widget or stop project or
|
||||
// clean stop/start fields of widget
|
||||
|
||||
Serial.print("Таймер: ");
|
||||
Serial.println(pump1.GetCurrentDuration());
|
||||
|
||||
pump1.Start();
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V4) // Кнопка помпы 1
|
||||
{
|
||||
pump1.Start();
|
||||
}
|
||||
|
||||
//BLYNK_WRITE(V5) // Таймер
|
||||
//{
|
||||
// int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
|
||||
// Serial.print("V1 Slider value is: ");
|
||||
// Serial.println(pinValue);
|
||||
// run_pump();
|
||||
//}
|
||||
// Motor M1(0x2D,_MOTOR_A, 1000); // Адрес, мотор, частота
|
||||
|
||||
@ -1 +1,68 @@
|
||||
class Pump
|
||||
{
|
||||
unsigned long lastTime;
|
||||
int duration = 10; // Время полива **************************
|
||||
|
||||
int maxDuration; // Максимальное время полива
|
||||
int currentDuration; // Текущее время полива для отображения в приложении
|
||||
|
||||
public:
|
||||
Pump(){ // int address, char motor, int freq
|
||||
// Motor M1(0x2D,_MOTOR_A, 1000); // Адрес, мотор, частот
|
||||
|
||||
_m = new Motor(0x2D, _MOTOR_A, 1000);
|
||||
lastTime = millis();
|
||||
currentDuration = 0;
|
||||
Serial.println("Pump created");
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if ((millis() - lastTime) > duration * 1000) // Пора выключать
|
||||
{
|
||||
Serial.println("Update-stop");
|
||||
_m -> setmotor(_STOP);
|
||||
}
|
||||
}
|
||||
|
||||
void Start(){
|
||||
// if (!IsON())
|
||||
// {
|
||||
Serial.print("Start! ");
|
||||
Serial.println(duration);
|
||||
lastTime = millis();
|
||||
_m -> setmotor(_CCW, 100);
|
||||
Update();
|
||||
// }
|
||||
}
|
||||
|
||||
void Stop(){
|
||||
// if (IsON())
|
||||
// {
|
||||
Serial.print("Stop! ");
|
||||
Serial.println(duration);
|
||||
lastTime = millis();
|
||||
_m -> setmotor(_STOP);
|
||||
Update();
|
||||
// }
|
||||
}
|
||||
|
||||
int GetCurrentDuration(){
|
||||
// if (IsON()) // Если помпа включена
|
||||
// {
|
||||
return ((millis() - lastTime) / 1000); // Текущее время полива
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
}
|
||||
|
||||
void SetDuration(int d){
|
||||
duration = d;
|
||||
Serial.print("SetDuration ");
|
||||
Serial.println(duration);
|
||||
}
|
||||
|
||||
private:
|
||||
Motor *_m;
|
||||
};
|
||||
|
||||
@ -1 +0,0 @@
|
||||
|
||||
@ -1 +1 @@
|
||||
|
||||
Pump pump1;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
void setup(void)
|
||||
{
|
||||
|
||||
Serial.begin(115200);
|
||||
delay(100);
|
||||
|
||||
@ -16,19 +17,22 @@ void setup(void)
|
||||
|
||||
timer.setInterval(1000L, timerEvent);
|
||||
|
||||
bool b = 1;
|
||||
float f = 100000;
|
||||
int i = 5;
|
||||
Serial.print("***** b *****");
|
||||
Serial.println(sizeof(b));
|
||||
|
||||
Serial.print("***** f *****");
|
||||
Serial.println(sizeof(f));
|
||||
|
||||
Serial.print("***** i *****");
|
||||
Serial.println(sizeof(i));
|
||||
|
||||
EEPROM.begin(512);
|
||||
// bool b = 1;
|
||||
// float f = 100000;
|
||||
// int i = 5;
|
||||
// Serial.print("***** b *****");
|
||||
// Serial.println(sizeof(b));
|
||||
//
|
||||
// Serial.print("***** f *****");
|
||||
// Serial.println(sizeof(f));
|
||||
//
|
||||
// Serial.print("***** i *****");
|
||||
// Serial.println(sizeof(i));
|
||||
//
|
||||
// EEPROM.begin(512);
|
||||
|
||||
// CreateObjects();
|
||||
readSettings();
|
||||
pump1.Stop();
|
||||
|
||||
}
|
||||
|
||||
27
y10_fun.ino
27
y10_fun.ino
@ -6,26 +6,37 @@ void timerEvent()
|
||||
|
||||
void refreshApp()
|
||||
{
|
||||
Blynk.virtualWrite(V5, pump1.GetCurrentDuration());
|
||||
Blynk.virtualWrite(V4, pump1.IsON());
|
||||
// Blynk.virtualWrite(V5, pump1.GetCurrentDuration());
|
||||
// Blynk.virtualWrite(V4, pump1.IsON());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void read_DHT22()
|
||||
{
|
||||
Temperature = dht.readTemperature();
|
||||
Humidity = dht.readHumidity();
|
||||
float Temperature = dht.readTemperature();
|
||||
float Humidity = dht.readHumidity();
|
||||
|
||||
// Serial.print("Температура: ");
|
||||
// Serial.println(Temperature, 2);
|
||||
// Serial.print("Влажность: ");
|
||||
// Serial.println(Humidity, 2);
|
||||
// Serial.print("Температура: ");
|
||||
// Serial.println(Temperature, 2);
|
||||
// Serial.print("Влажность: ");
|
||||
// Serial.println(Humidity, 2);
|
||||
|
||||
Blynk.virtualWrite(V3, Temperature);
|
||||
Blynk.virtualWrite(V2, Humidity);
|
||||
}
|
||||
|
||||
void setPumpDuration(int v0){
|
||||
int d = v0;
|
||||
// pump1.SetDuration(d);
|
||||
Serial.print("Длительность: ");
|
||||
Serial.println(d);
|
||||
}
|
||||
|
||||
void blynk_connected(){
|
||||
Blynk.syncAll();
|
||||
}
|
||||
|
||||
// void writeSettings(){ // Для сохранения настроек в EEPROM
|
||||
// EEPROM.update(0, pump1.GetCurentDuration();
|
||||
//}
|
||||
|
||||
24
z15_Blink_RW.ino
Normal file
24
z15_Blink_RW.ino
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
BLYNK_WRITE(V0) // Длительность полива первой помпы
|
||||
{
|
||||
setPumpDuration(param.asInt());
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V1) // Установка времени старта полива
|
||||
{
|
||||
// You'll get HIGH/1 at startTime and LOW/0 at stopTime.
|
||||
// this method will be triggered every day
|
||||
// until you remove widget or stop project or
|
||||
// clean stop/start fields of widget
|
||||
|
||||
Serial.print("Таймер: ");
|
||||
// Serial.println(pump1.GetCurrentDuration());
|
||||
|
||||
// pump1.Start();
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V4) // Кнопка помпы 1
|
||||
{
|
||||
pump1.Start();
|
||||
}
|
||||
10
z999_.ino
Normal file
10
z999_.ino
Normal file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
Motor M1(0x2D,_MOTOR_A, 1000); // Адрес, мотор, частота
|
||||
https://compacttool.ru/wemos-d1-mini-drajver-kollektornykh-motorov-tb6612fng
|
||||
|
||||
Пример auth.h
|
||||
char auth[] = "Fdj2ndHfZmRirtgrgdrfh81fzPpfB0-";
|
||||
char ssid[] = "WIFI";
|
||||
char pass[] = "132password";
|
||||
|
||||
*/
|
||||
Loading…
x
Reference in New Issue
Block a user