#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Servo.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27,20,4);
char auth[] = "qB9NkoCmZnum53mJqLFgy31cIEjKnLgc";
char ssid[] = "jia0802_2.4GHz@unifi";
char pass[] = "pass";
int buzzer = 5;
SoftwareSerial EspSerial(2, 3); // tx , rx
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
WidgetRTC rtc;
Servo servo;
void cradle()
//you begin your own personal code for servo here
{
int pos;
for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
// in steps of 1 degree
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
for (pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
//your personal code for servo should end her
}
BLYNK_WRITE(V3)
{
int pinValue = param.asInt();
if (pinValue == 1) { // if Button sends 1
cradle(); // start the function cradle
Blynk.run(); // Run rest of show in-between waiting for this loop to repeat or quit.
int pinValue = 0; // Set V3 status to 0 to quit, unless button is still pushed (as per below)
Blynk.syncVirtual(V3); // ...Then force BLYNK_WRITE(V3) function check of button status to determine if repeating or done.
}
}
void clockDisplay()
{
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + " " + month() + " " + year();
Serial.print("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
// Send time to the App
Blynk.virtualWrite(V4, currentTime);
// Send date to the App
Blynk.virtualWrite(V5, currentDate);
}
void setup()
{
lcd.init();
lcd.init();
lcd.backlight();
lcd.setCursor(1, 0);
lcd.print(" Welcome to the ");
delay(2000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print(" Cat Feeder ");
delay(2000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print(" Created By:");
delay(2000);
lcd.clear();
lcd.setCursor(1, 1);
lcd.print("Amirul Syazwan");
delay(2000);
lcd.clear();
lcd.setCursor(1, 1);
lcd.print("Amir Ikram");
delay(2000);
lcd.clear();
lcd.setCursor(1, 1);
lcd.print("Dan");
delay(2000);
lcd.clear();
lcd.setCursor(1, 1);
lcd.print("Sabri");
delay(2000);
lcd.clear();
Serial.begin(9600);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
servo.attach(12);
rtc.begin();
timer.setInterval(10000L, clockDisplay);
}
void loop()
{
Blynk.run();
timer.run();
// Turn off the display;
lcd.noDisplay();
delay(500);
// Turn on the display;
lcd.display();
delay(500);
}
@Wan_Syazwan please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Pete.
done
You’ve edited the code, but added the wrong characters at the beginning and end of your code, despite me providing you with triple backticks that you can copy/paste.
Please try again.
Pete.
You should read this…
You also have some strange and misleading statements in your comments…
Your board doesn’t run multiple code threads simultaneously. The cradle
function executes fully before the Blynk.run
command is executed, not during the for
loop within the cradle
function.
Also, what is the purpose of this line of code…
Pete.
Sorry, your multiwifi tag made me think that you were using an ESP8266 as your main board, not an Arduino, but I see from the included libraries this isn’t the case.
It is always a good idea to provide the information that is requested when you first create the topic.
Pete.
so my code right or not ?
No, as I said before.
Pete.
What’s wrong with my code can you tell me clearly
Have you read and understood the ‘keep your void loop clean’ document?
Pete.
#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Servo.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27,16,2);
char auth[] = "qB9NkoCmZnum53mJqLFgy31cIEjKnLgc";
char ssid[] = "jianifi";
char pass[] = "nswwwwwwwwwwwwwwwwwwwwwwwwww";
int buzzer = 5;
SoftwareSerial EspSerial(2, 3); // tx , rx
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
WidgetRTC rtc;
Servo servo;
void cradle()
//you begin your own personal code for servo here
{
int pos;
for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
// in steps of 1 degree
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
for (pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
//your personal code for servo should end her
}
BLYNK_WRITE(V3)
{
int pinValue = param.asInt();
if (pinValue == 1) { // if Button sends 1
cradle(); // start the function cradle
Blynk.run(); // Run rest of show in-between waiting for this loop to repeat or quit.
int pinValue = 0; // Set V3 status to 0 to quit, unless button is still pushed (as per below)
Blynk.syncVirtual(V3); // ...Then force BLYNK_WRITE(V3) function check of button status to determine if repeating or done.
}
}
void clockDisplay()
{
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + " " + month() + " " + year();
Serial.print("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
// Send time to the App
Blynk.virtualWrite(V4, currentTime);
// Send date to the App
Blynk.virtualWrite(V5, currentDate);
}
BLYNK_CONNECTED() {
// Synchronize time on connection
rtc.begin();
}
void setup()
{
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Welcome to the");
lcd.setCursor(0, 1);
lcd.print("Cat Feeder");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Created By:");
lcd.setCursor(0, 1);
lcd.print("Amirul");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Amir dan Sabri");
delay(2000);
lcd.clear();
Serial.begin(9600);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
servo.attach(12);
timer.setInterval(1000L, clockDisplay);
lcd.noDisplay();
delay(500);
lcd.display();
delay(500);
}
void loop()
{
Blynk.run();
timer.run();
}
i have clear my void loop