Hi all,
I am working on a project with a servo controller fish feeder; I’d like to be able to set the time interval between feeding and also the amount of movements per feeding cycle via the Blynk app (V2 and V3 slider value), I cant seem to manage how to read the amount of movements and then the deep sleep time out; can someone check my script and help me out? Thanks!
/*************************************************************
Rotate a servo using a slider!
App project setup:
Slider widget (0...180) on V3
*************************************************************/
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "TMPLc1QkS5Mj"
#define BLYNK_DEVICE_NAME "Quickstart Device"
#define BLYNK_AUTH_TOKEN "glCMTbwumW-H3I_HlyfPweDDRItCiXkK"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ZiggoECAA631";
char pass[] = "Broezdevries121";
Servo servo;
BLYNK_CONNECTED(){
Blynk.syncAll() ;
int pinValue;
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);}
BLYNK_WRITE(V3)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("Aantal voeren is: ");
Serial.println(pinValue);
if (pinValue == 1) {
servo.write(0);
delay(5000);
servo.write(180);
delay(2000);
servo.write(0);
delay(20000);}
if (pinValue == 2) {
servo.write(0);
delay(5000);
servo.write(180);
delay(2000);
servo.write(0);
delay(5000);
servo.write(180);
delay(2000);
servo.write(0);
delay(20000);}
if (pinValue == 3) {
servo.write(0);
delay(5000);
servo.write(180);
delay(2000);
servo.write(0);
delay(5000);
servo.write(180);
delay(2000);
servo.write(0);
//}
delay(20000);}
}
BLYNK_WRITE(V2)
{ int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("Sleep value is: ");
Serial.println(pinValue);
ESP.deepSleep(pinValue*10000000); // 10 second sleep
//BLYNK_WRITE(V2)
//{
// int pinValue=param.asInt();
//Serial.print ("Time value is: ");
//Serial.print(pinValue);
// if (pinValue == 1) {
// servo.write(0);
// delay(5000);
// servo.write(180);
// delay(2000);
// servo.write(0);
// delay(20000);
//Serial.print ("Time value is: ");
// Serial.print(pinValue);
// ESP.deepSleep(pinValue*10000000); // 10 second sleep
//}
//}
unsigned long startTime = 0;
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
servo.attach(2);
}
void loop()
{
Blynk.run();
}