Hello!
Just wrote a Sketch for my roller shutter to open and Close but when i want to compile it, it alwas says “a function-definition is not allowed here before ‘{’ token” after a Loop.
Why is that?
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3); // RX, TX
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>
#include <SimpleTimer.h>
#include <Time.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
SimpleTimer timer;
void setup()
{
pinMode(4, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
SwSerial.begin(9600);
Blynk.begin(auth);
// Default baud rate is 9600. You could specify it like this:
//Blynk.begin(auth, 57600);
}
BLYNK_WRITE(V5) //Button Widget is writing to pin V5
{
if (param.asInt()){
digitalWrite(4, HIGH);
}
else {
digitalWrite(4, LOW);
}
void checkPin()
{
int taster = analogRead(5);
if (taster == HIGH) {
Blynk.virtualWrite(5, 1) // update the state of the Button Widget in the app
}
}
void loop()
{
Blynk.run();
checkPin();
}
also you can shorten your code a bit if you want to:
BLYNK_WRITE(V5) //Button Widget is writing to pin V5
{
(param.asInt()) ? digitalWrite(4, HIGH) : digitalWrite(4, LOW);
}
void checkPin()
{
int taster = analogRead(5);
if (taster == HIGH) Blynk.virtualWrite(5, 1); // update the state of the Button Widget in the app
}
ok but i thought (maybe you can help me with that ) that with the first push the roller shutter moves down; when i push the button a 2nd time within x seconds the roller shutter stops and when i push it a third time the roller shutter moves up
yeah with two relays cause the Motor for the roller shutter has two extra cables for up and down so i only have to switch between the relays. Also the Motor has an automatic stop so i dont Need a timer or something like that.
For the Controlling i have a push button in my room connected to an analog Arduino port so i want to be able to use this 1.2.3 push function i told you before in the blynk app and with the button in my room.
Is that possible and could you give me a Code for that cause im really bad in coding
Ok but your physical button has to be wired in appropriate way, if you really really wanna do it there is smart way. You need to wire up physical button with pull up resistor basically see in google how to wire up button. Then you attach interrupt on some of the pins to detect pressed button and execute checkPin (it’s not necessary to put it inside loop). Lastly for BLYNK_WRITE, when you detect param.asInt() equal to 1 then you can set SimpleTimer callback function to execute once after 1s (digitalWrite low on predefined pin, and writeLow on Switch button). That would be basic concept.
Aufgrund deines Namens gehe ich mal davon aus dass du Deutscher bist
Kannst du mir evtl. ein Sketch oder Beispiel Code zukommen lassen indem die Funktionen enthalten sind (1. Drücken Rollo runter;2. mal innerhalb zeit x bleibt stehen; 3. fährt wieder hoch mit App und Taster im Raum) hab ich ja oben schon mal erklärt