C programming on esp8266 arduino ide

error message "expected declaration before '}' token"

which refers to the code section:
"// Audio state
enum AudioState { IDLE, ONIDLE, ONVERYLOW, ONLOW, ONMID, ONHIGH };
AudioState audioState = IDLE; "

where is the error?
did I declare it too much, when the audio statete is just { idle, onidle, onverylow } there is no error,

probably in the lines you did not post.

Also Please correct your post and add code tags around your code.

There is a small pencil image below your existing posts.

  • click on this pencil ➜ that will let you edit your post.
  • Select the part of the text that corresponds to the code
  • Click on the <code/> icon in the toolbar to indicate that it is code
  • click image Save Edit

(Also make sure to properly indent the code in the IDE before copying and pasting it here. This can be done by pressing ctrlT on a PC or cmdT on a Mac)

this is perfectly fine

enum AudioState { IDLE, ONIDLE, ONVERYLOW, ONLOW, ONMID, ONHIGH };
AudioState audioState = IDLE;

so you did not tell the full story . When compiling the error message is

sketch_feb24a.ino:33:44: note: in expansion of macro 'ONLOW'
 enum AudioState { IDLE, ONIDLE, ONVERYLOW, ONLOW, ONMID, ONHIGH };  // Pastikan tidak ada koma di akhir
                                            ^~~~~
sketch_feb24a:33:65: error: expected declaration before '}' token

The compiler is giving you a key information when it states "in expansion of macro 'ONLOW"

➜ it means ONLOW is defined somewhere else and probably the same applies to ONHIGH

try to change all your ONLOW and ONHIGH in the code to something else like

enum AudioState { IDLE, ONIDLE, ONVERYLOW, ONLOW_CHANGED, ONMID, ONHIGH_CHANGED };

and see if you still have the issue.

found it ➜ if you are on ESP32, look at the file esp32-hal-gpio.h

it contains

so your enum was changed into

enum AudioState { IDLE, ONIDLE, ONVERYLOW, 0x04, ONMID, 0x05 };

and it just does not make any sense, hence the error.

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