A function-definition is not allowed here before '{' token void setup(){

Hi i need your help with my code I don't know what i did wrong.
An error message saying: 30:15: error: a function-definition is not allowed here before '{' token
void setup(){
37:14: error: a function-definition is not allowed here before '{' token
void loop(){
Please can you help me anyone

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

#define LED_RED GPIO_NUM_5
#define LED_BLUE GPIO_NUM_4

void task_LED_RED(void *param);

void app_main(void) {
  xTaskCreate(task_LED_RED, "task_RED", 1, NULL, 3, NULL);
}

void task_LED_RED(void *param) {
  
  void setup(){
  
    const int resolution = 13;
    const int freq_hz_red = 1;
    const int ledChannel_red = 0;
  }

  void loop(){
    for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){   
    ledcWrite(ledChannel_red, dutyCycle);
    delay(15);
    }
    for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
      ledcWrite(ledChannel_red, dutyCycle);
      delay(15);
    }
  }
}

You can't define a function inside another function.

1 Like

Where i need to write setup() and loop()? If I remove this, I will have error: undefined reference to `setup()'

You have two functions defined in the function task_LED_RED.

1 Like

Move setup() and loop() outside of the task_LED_RED() function. C++ does not allow defining a function within a function.

1 Like

You also need to consider the limited scope of the constants defined in setup()

2 Likes

Thanks to everybody!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.