Hi!
I think I have some problems with using digitalWrite
function.
My code:
// --------- LIBRARIES -------------
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>
// ----------- VARIABLES ---------------
// Set Blynk token.
char auth[] = "xxx";
// Define SSID and Password for a WiFi network
char ssid[] = "xxx";
char pass[] = "xxx";
// Define PINs which are connected to a faucet relay
byte faucet1_pin = 5;
// --------- FUNCTIONS --------------
void setup()
{
// Debug console
Serial.begin(115200);
delay(10);
// preparing GPIOs
pinMode(faucet1_pin, OUTPUT);
digitalWrite(faucet1_pin, LOW);
// Connect to the WiFI and Blynk server
Blynk.begin(auth, ssid, pass);
}
BLYNK_WRITE(V1) {
TimeInputParam t(param);
// Process start time
if (t.hasStartTime())
{
Serial.println(String("Start: ") +
t.getStartHour() + ":" +
t.getStartMinute() + ":" +
t.getStartSecond());
digitalWrite(faucet1_pin, HIGH);
}
else if (t.isStartSunrise())
{
Serial.println("Start at sunrise");
digitalWrite(faucet1_pin, HIGH);
}
else if (t.isStartSunset())
{
Serial.println("Start at sunset");
digitalWrite(faucet1_pin, HIGH);
}
else
{
// Do nothing
}
// Process stop time
if (t.hasStopTime())
{
Serial.println(String("Stop: ") +
t.getStopHour() + ":" +
t.getStopMinute() + ":" +
t.getStopSecond());
digitalWrite(faucet1_pin, LOW);
}
else if (t.isStopSunrise())
{
Serial.println("Stop at sunrise");
digitalWrite(faucet1_pin, LOW);
}
else if (t.isStopSunset())
{
Serial.println("Stop at sunset");
digitalWrite(faucet1_pin, LOW);
}
else
{
// Do nothing: no stop time was set
}
// Process timezone
// Timezone is already added to start/stop time
Serial.println(String("Time zone: ") + t.getTZ());
// Get timezone offset (in seconds)
Serial.println(String("Time zone offset: ") + t.getTZ_Offset());
// Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
for (int i = 1; i <= 7; i++) {
if (t.isWeekdaySelected(i)) {
Serial.println(String("Day ") + i + " is selected");
}
}
}
void loop()
{
Blynk.run();
}
And I have two problems:
- My NodeMCU doesn’t connect to Wi-Fi when I try to prepare pin state in the
setup()
function. Everything is working fine when I comment that code.
// preparing GPIOs
pinMode(faucet1_pin, OUTPUT);
digitalWrite(faucet1_pin, LOW);
- Nothing happens when I set a schedule in a Time input widget, but I expect to work
BLYNK_WRITE(V1)
I suspect the problem is in using digitalWrite
function with the wrong way, but I don’t understand what exactly I’ve done wrong.