error: expected unqualified-id before '{' token

hello everybody,

i'm really new to programming enviroment and i am facing some problems

i'd made this programm in order to read the values from remote control and open or close the relay. Also i wanted to control it via serial monitor, in order when i press the number 3 the remote will close and the number 1 opens. But in compiling im facing this: IRrelay:62: error: expected unqualified-id before '{' token

The code is copied-pasted from another guy which has done something similar for leds. Although i have made some adjustments

#include <IRremote.h>


int relay_pin = 5;
int recv_pin = 7;
int actual_state = LOW;

IRrecv irrecv(recv_pin);
decode_results results;


void setup() {
    pinMode(relay_pin, OUTPUT);
    Serial.begin(9600);
    irrecv.enableIRIn(); // Start the receiver
}

void loop() {
    if (irrecv.decode(&results)) {
        Serial.println(results.value, HEX);
        if (results.value == 0xffa25d) 
        { // On/Off button
            actual_state = (actual_state == LOW) ? HIGH : LOW;
            digitalWrite(relay_pin, actual_state);
        }
        if (results.value == 0x0080c) 
        { // On/Off button
            actual_state = (actual_state == LOW) ? HIGH : LOW;
            digitalWrite(relay_pin, actual_state);
        }
        if (results.value == 0x00c) 
        { // On/Off button
            actual_state = (actual_state == LOW) ? HIGH : LOW;
            digitalWrite(relay_pin, actual_state);
        }
        irrecv.resume(); // Receive the next value
    }
    if (Serial.available()) {

    //read serial as ascii integer
    int ser = Serial.read();
    
    //Print the value in the serial monitor
    Serial.println(ser);

     if(ser >= 48 && ser <= 57){    
      //The ascii equivilent of numbers 0 - 9 are 48 - 57
      // so subtracting 46 from the ascii gives us 2 - 12 (the pins we want to use)
      int usePin = ser - 46;
      int shutPin = ser - 46;

      int triggerPin(usePin);
      
      
     }

  }

}
{
void triggerPin(int pin){
  digitalWrite(pin, HIGH);
}

void ser(int num){
 if(num = 49){
    digitalWrite(pin, LOW);
}
}
}
}
{
void triggerPin(int pin){

Well, that was easy.

AWOL:

{

void triggerPin(int pin){



Well, that was easy.

excuse me but i dont understand what you have changed in the code :smiley:

Unlike some other programming languages, C++ doesn't allow functions declared inside other functions or blocks. Look at the line being flagged and if it is the start of a new function you may not have put a close bracket on the previous function.

Yes

after removing the bracket before void, i am facing this:

IRrelay.ino: In function 'void ser(int)':
IRrelay:69: error: 'pin' was not declared in this scope
IRrelay.ino: At global scope:
IRrelay:73: error: expected declaration before '}' token

How i get over this ?

toketog:
after removing the bracket before void, i am facing this:

IRrelay.ino: In function 'void ser(int)':

IRrelay:69: error: 'pin' was not declared in this scope
IRrelay.ino: At global scope:
IRrelay:73: error: expected declaration before '}' token




How i get over this ?

By looking to see where you declared the variable called pin

It must be declared in the function, or globally (outside all functions).