0

was working on seven segment display and deleted unnecessary lines of code

a function-definition is not allowed here before '{' token error in arduino IDE

full code: main problem in void loop where the error message above displays

Tagged and Spoiler are lines that are highlighted for error

#include <IRremote.h>

const int RECV_PIN = 13;
int buzzer = 12;



/*
                         A
                      --------
                     |        |
                  F  |        |  B
                     |   G    |
                      --------
                     |        |                  
                  E  |        |  C
                     |        |
                      --------
                          D
pins are from left to right on board for both flipped and unflipped
middle pins are ground
leave out pin on far right

pin 1 = e to gpio 6
pin 2 = d to gpio s
pin 3 = gnd
pin 4 = c to gpio 4
pin 6 = b to gpio 3
pin 7 = a to gpio 2
pin 8 = gnd
pin 9 = f to gpio 7
pin 10 = g to gpio 8
 
Array for this =
  A   B   C   D   E   F   G
{ x,  x,  x,  x,  x,  x,  x,}, for the sev seg to display witch segments are on
1 = on
0 = off
*/
//the array of numbers for the sev.seg. in binary form

int num_array[10][7] = { { 1, 1, 1, 1, 1, 1, 0 },    // 0
                         { 0, 1, 1, 0, 0, 0, 0 },    // 1
                         { 1, 1, 0, 1, 1, 0, 1 },    // 2
                         { 1, 1, 1, 1, 0, 0, 1 },    // 3
                         { 0, 1, 1, 0, 0, 1, 1 },    // 4
                         { 1, 0, 1, 1, 0, 1, 1 },    // 5
                         { 1, 0, 1, 1, 1, 1, 1 },    // 6
                         { 1, 1, 1, 0, 0, 0, 0 },    // 7
                         { 1, 1, 1, 1, 1, 1, 1 },    // 8
                         { 1, 1, 1, 0, 0, 1, 1 } };  // 9

int num_array_2[10][7] = {{ 0, 1, 1, 1, 1, 1, 0 },     //u
                          { 1, 1, 1, 1, 1, 1, 0 },    //o
                          { 0, 1, 1, 1, 0, 1, 1 },    //y
                          { 1, 0, 1, 0, 1, 1, 1 },    //k
                          { 1, 0, 0, 1, 1, 1, 0 },    //c
                          { 0, 1, 1, 1, 1, 1, 0 },    //u
                          { 1, 0, 0, 0, 1, 1, 1 }};  //f


IRrecv irrecv(RECV_PIN);  //connection to IR pin
decode_results results;   // decode to 0x

void Num_Write(int);

void Num_Write(int number)  //custom function to increment numbers from the array
{
  int pin = 2;
  for (int n = 0; n < 7; n++) {
    digitalWrite(pin, num_array[number][n]);
    pin++;
  }
}

void Num_Write_2(int);

void Num_Write_2(int number)  //custom function to increment numbers from the array
{
  int pin = 2;
  for (int n = 0; n < 7; n++) {
    digitalWrite(pin, num_array_2[number][n]);
    pin++;
  }
}


void setup() {
  Serial.begin(9600);   //start connection to serial monitor
  irrecv.enableIRIn();  //start receiver and check if any signals come through

  pinMode(2, OUTPUT);  //All seven segment pins to output
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(buzzer, OUTPUT);

[tag:void loop() {]
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);  //decode these results into hex value then keep checking for new signals
    irrecv.resume();
  }
  switch (results.value) {  //hex codes to look out for
    case 0x138C:
    case 0x1BAC:

      tone(buzzer, 200, 850);
      // noTone(buzzer);
      // delay(850);
      //tone(buzzer,1500,1000)
      for (int counter = 10; counter > 0; --counter)  //if the hex codes above are detected start counter from ten and decrement counter by one
      {
        delay(1000);
        Num_Write(counter - 1);  // custom func decrement from 10 to 0
      }
      delay(300);
  }
  switch (results.value) {
    case 0x13AD:
    case 0x1BAD:

      tone(buzzer, 200, 850);
      // noTone(buzzer);
      // delay(850);
      //tone(buzzer,1500,1000)
      for (int counter = 10; counter > 0; --counter)  //if the hex codes above are detected start counter from ten and decrement counter by one
      {
        delay(100);
        Num_Write_2(counter - 1);  // custom func decrement from 10 to 0
      }
      delay(300);
  }
>! }

I tried on a different sketch hoping it was a fluke and re formatting the code but i cant seem to solve the problem where it was working fine around 30 mins ago

from what I can tell this can be traced from the "function definition is not allowed" from researching on the internet this is due to improper indentation but I cant seem to find any missing brackets or similar syntax missing

I hope someone could fix this problem for me

0 Answers0