A function-definition is not allowed here before '{' token?

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();
  
}

Your V5 function is missing the closing braces and ; from the last line of the checkPin() function.

1 Like

Your Blynk.virtualWrite(5, 1) a semi-colon is missing.

1 Like

Thx!
Now it works fine :smile:

Thx!
It works now :smiley:

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 
}

the Code works now but my button “taster” is a push and not a Switch button and i think because of this the Sketch won`t work :confused:

could you help me?

Yep if your V5 Button is push button not a switch one checkPin function wont do anything really. You need to change it to switch button.

ok but i thought (maybe you can help me with that :slight_smile: ) 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

how exactly you control rolling shutter? Relay?

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 :sweat_smile:

What does checkPin function do exactly as what it checks for? You didn’t set the pin 5 to anything so it’s kinda awkward. What do you have on pin 5??

Pawel gave me the Code for the physical state sync! Heres what he answered to me:

1.Attach Blynk app button to Virtual Pin 5 (for example)
2.Write a code to trigger your roller shutter over a Virtual Pin:

BLYNK_WRITE(V5) //Button Widget is writing to pin V1
{
  if (param.asInt()){
    //rotate roller shutter for N seconds
  }
}

When physical button is pressed perform Blynk.virtualWrite(V5, 1) - this will turn Button in the app ON. Here is a pseudo code:

if (button is pressed) {
  Blynk.virtualWrite(5, 1) // update the state of the Button Widget in the app 
}

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.

Could you give me a Code example for that cause that would me help a lot :slight_smile:

This would be nice tutorial

Ok but what do you mean with simpletimer callback?

To use the SimpleTimer timer also for executing the checkPin void with a short interval. That way it will always update after one second.

Aufgrund deines Namens gehe ich mal davon aus dass du Deutscher bist :wink:
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 :smiley:

Ich bin nähmlich echt nicht gut im Coden :confused:

I’m sorry but I don’t speak much German, I’m actually Dutch :slight_smile: