Hi there,
As I was creating the code to control my automated windows, I came across something I was not expecting. Integers, functions and all other stuff I have declared in my code don’t word within BLYNK_WRITE(vpin) {}. Everytime I call a function from within BLYNK_WRITE(vpin) I get ‘function’ was not declared in this scope, although I need that function to be callen when the vpin gets changed. How do I get around this?
Cheers,
Emiel
In that case, you’re doing something odd in your code.
Post the full code (correctly formatted with triple backticks) and we’ll take a look at it.
Pete.
/*
IN1 -> IO16
IN2 -> IO17
IN3 -> IO25
IN3 -> IO26
*/
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "[redacted]";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "[redacted]";
char pass[] = "[redacted]";
char server[] = "192.168.8.2";
int port = 8080;
int raamAvailable1 = 1;
int raamAvailable2 = 1;
int timer1 = 0;
int timer2 = 0;
void setup()
{
// Debug console
Serial.begin(115200);
// Blynk setup and begin
Blynk.begin(auth, ssid, pass, server, port);
// Set pins connected to motor board as output
pinMode(16, OUTPUT);
pinMode(17, OUTPUT);
pinMode(25, OUTPUT);
pinMode(26, OUTPUT);
// Put the windows up
raam1Up();
raam2Up();
Blynk.virtualWrite(V1, 1);
Blynk.virtualWrite(V2, 1);
}
void loop()
{
Blynk.run();
}
BLYNK_WRITE(V1) {
int pinValue = param.asInt();
if (pinValue == 1) {
raam1Up();
}
if (pinValue == 0) {
raam1Down();
}
}
BLYNK_WRITE(V2) {
int pinValue = param.asInt();
if (pinValue == 1) {
raam2Up();
}
if (pinValue == 0) {
raam2Down();
}
}
void raamAvailability1() {
if (timer1 + 30000 <= millis()) {
raamAvailable1 = 1;
}
}
void raamAvailability2() {
if (timer2 + 30000 <= millis()) {
raamAvailable2 = 1;
}
}
void raam1Up() {
if {raamAvailable == 1) {
digitalWrite(16, HIGH);
digitalWrite(17, LOW);
Serial.println("Raam 1 omhoog");
raamAvailable1 = 0;
timer1 = millis();
}
}
void raam2Up() {
if (raamAvailable == 1) {
digitalWrite(25, HIGH);
digitalWrite(26, LOW);
Serial.println("Raam 2 omhoog");
raamAvailable2 = 0;
timer2 = millis();
}
}
void raam2Down() {
if (raamAvailable == 1) {
digitalWrite(25, LOW);
digitalWrite(26, HIGH);
Serial.println("Raam 2 omlaag");
raamAvailable2 = 0;
timer2 = millis();
}
}
void raam1Down() {
if (raamAvailable == 1) {
digitalWrite(16, LOW);
digitalWrite(17, HIGH);
Serial.println("Raam 1 omlaag");
raamAvailable1 = 0;
timer1 = millis();
}
}
There you go
Edit: This is a draft of my code, and it probably doesnt even work. Just saying
Edit 2: Also, I am too lazy to write the code to connect, hence the standard comments 
In that case I won’t try delving into it too hard!
My advice would be to add some serial print statements. Print the value of pinValue in your BLYNK_WRITE functions and print “I’m here’ messages at the very start of your raamxxx functions, along with the values of the variables like raamAvailable that are subsequently used in ‘if’ statements.
Pete.
Well a ‘draft’ is an axeggeration, it’s just not finished yet. I am planning on using this code in the final product. I wouldn’t bother posting here if I didn’t want to use it. I would really appreciate if you take a look at it.
I also discovered that raamxxx() is not able to be called anywhere in my code, which makes it even more confusing… I’ll tidy up the code a little and post it here with some minor changes in a sec. @PeteKnight
/*
IN1 -> IO16 \ Raam 1
IN2 -> IO17 /
IN3 -> IO25 \ Raam 2
IN3 -> IO26 /
The windows (raam) switch direction if you switch + and -. They are driven by a L298N driver.
*/
#define BLYNK_PRINT Serial
// Libraries
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Authorization token
char auth[] = "[redacted]";
// WiFi credentials and Blynk server.
char ssid[] = "[redacted]";
char pass[] = "[redacted]";
char server[] = "[redacted]";
int port = [redacted];
// Global variables (are global variables bad?)
int raamAvailable1 = 1;
int raamAvailable2 = 1;
int timer1 = 0;
int timer2 = 0;
void setup()
{
// Debug console.
Serial.begin(115200);
// Blynk setup and begin.
Blynk.begin(auth, ssid, pass, server, port);
// Set pins connected to motor board as output.
pinMode(16, OUTPUT);
pinMode(17, OUTPUT);
pinMode(25, OUTPUT);
pinMode(26, OUTPUT);
// Put the windows up
raam1Up();
raam2Up();
//Updating the status of the virtual pins manually just to be sure they display accurate information on the app.
Blynk.virtualWrite(V1, 1);
Blynk.virtualWrite(V2, 1);
}
void loop()
{
Blynk.run();
}
// The windows can't switch direction while they're runnning in a certain direction, so I put in a delay before the windows become available again.
void raamAvailability1() {
if (timer1 + 30000 <= millis()) {
raamAvailable1 = 1;
}
}
// Same for the second window.
void raamAvailability2() {
if (timer2 + 30000 <= millis()) {
raamAvailable2 = 1;
}
}
// raamxxx() to put the windows up or down.
void raam1Up() {
if {raamAvailable1 == 1) {
digitalWrite(16, HIGH);
digitalWrite(17, LOW);
Serial.println("Raam 1 omhoog");
raamAvailable1 = 0;
timer1 = millis();
}
}
void raam2Up() {
if (raamAvailable2 == 1) {
digitalWrite(25, HIGH);
digitalWrite(26, LOW);
Serial.println("Raam 2 omhoog");
raamAvailable2 = 0;
timer2 = millis();
}
}
void raam2Down() {
if (raamAvailable2 == 1) {
digitalWrite(25, LOW);
digitalWrite(26, HIGH);
Serial.println("Raam 2 omlaag");
raamAvailable2 = 0;
timer2 = millis();
}
}
void raam1Down() {
if (raamAvailable1 == 1) {
digitalWrite(16, LOW);
digitalWrite(17, HIGH);
Serial.println("Raam 1 omlaag");
raamAvailable1 = 0;
timer1 = millis();
}
}
BLYNK_WRITE(V1) {
int pinValue = param.asInt();
if (pinValue == 1) {
raam1Up();
}
if (pinValue == 0) {
raam1Down();
}
Serial.println(pinValue);
}
BLYNK_WRITE(V2) {
int pinValue = param.asInt();
if (pinValue == 1) {
raam2Up();
}
if (pinValue == 0) {
raam2Down();
}
}
I don’t get why all raamXXX() functions are not able to be called anywhere in the code?
OK I found the problem. On line 76 there’s a {
instead of a (
1 Like