Expected unqualified id before switch

#include “thingProperties.h”
#include<Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;
void setup() {
Serial.begin(9600);
delay(1500);
while(!Serial);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
while(ArduinoCloud.connected() != 1) {
ArduinoCloud.update();
delay(500);
}
CARRIER_CASE=false;
carrier.begin();
delay(500);
}
void loop() {
ArduinoCloud.update();
if(warningAlarm==true){
alarm();
}
carrier.display.setCursor(50,100);
if(soundOn == true){
carrier.Buzzer.sound(soundFrequency);
delay(soundDuration);
carrier.Buzzer.noSound();
delay(soundDuration);
}
}
void alarm() {
carrier.display.fillScreen(ST77XX_RED);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(3);
carrier.display.setCursor(50,100);
carrier.display.println(“WARNING!”);
carrier.Buzzer.sound(1000);
delay(1000);
carrier.display.fillScreen(ST77XX_WHITE);
carrier.display.setTextColor(ST77XX_RED);
carrier.display.setTextSize(3);
carrier.display.setCursor(50,100);
carrier.display.println(“WARNING!”);
carrier.Buzzer.noSound();
delay(1000);
carrier.display.fillScreen(ST77XX_WHITE);
carrier.display.setTextColor(ST77XX_WHITE);
}
switch (number) {
case 1:
Break;
case 2:
Break;
case 25:
break;
}

welcome to the forums. Please take a moment or two and read the sticky post at the top of this topic to learn how to get the most out of this forum. You will learn how to post your code properly as well as how to post your entire error code. It will help people help you.
If you auto format your code (Ctrl-T in the IDE) it will show you where the code lines up vertically which will show you that your switch() statement it outside your loop() function which is not allowed.

#include “thingProperties.h”
#include<Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;
void setup() {
  Serial.begin(9600);
  delay(1500);
  while (!Serial);
  initProperties();
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  while (ArduinoCloud.connected() != 1) {
    ArduinoCloud.update();
    delay(500);
  }
  CARRIER_CASE = false;
  carrier.begin();
  delay(500);
}
void loop() {
  ArduinoCloud.update();
  if (warningAlarm == true) {
    alarm();
  }
  carrier.display.setCursor(50, 100);
  if (soundOn == true) {
    carrier.Buzzer.sound(soundFrequency);
    delay(soundDuration);
    carrier.Buzzer.noSound();
    delay(soundDuration);
  }
}
void alarm() {
  carrier.display.fillScreen(ST77XX_RED);
  carrier.display.setTextColor(ST77XX_WHITE);
  carrier.display.setTextSize(3);
  carrier.display.setCursor(50, 100);
  carrier.display.println(“WARNING!”);
  carrier.Buzzer.sound(1000);
  delay(1000);
  carrier.display.fillScreen(ST77XX_WHITE);
  carrier.display.setTextColor(ST77XX_RED);
  carrier.display.setTextSize(3);
  carrier.display.setCursor(50, 100);
  carrier.display.println(“WARNING!”);
  carrier.Buzzer.noSound();
  delay(1000);
  carrier.display.fillScreen(ST77XX_WHITE);
  carrier.display.setTextColor(ST77XX_WHITE);
}
switch (number) {
case 1:
  Break;
case 2:
  Break;
case 25:
  break;
}

Also, case matters; ‘Break’ != ‘break’

I’m afraid I do not understand how to go to tools in IDE to auto format as this sketch was written on web editor, where there is no tools bar. [I am a novice to ‘IoT’ & previously finished the Student Kit only.]

[quote=“blh64, post:2, topic:851443”]
your switch() statement it outside your loop() function which is not allowed.
[/quote].
I don’t understand this - I have tried shifting brackets around to no effect.
Thank you for your help & patience.

Chris

in the code listing posted by blh64, the switch statement at the bottom is outside of any function. the brace just before “switch” should follow the closing brace of the switch statement

Braces should not be shifted round at random, if only because there are too many wrong combinations and only one right one. You have to make them do what you want. If you put your cursor on a brace { or a bracket ( then the matching one, if there is one, should be highlighted. That way you can get them right.

It might be time to look up what they mean.

The error was that the code would not compile.

It is simply that in the original code the braces defining the function did not enclose the whole function. This meant the compiler could not understand the code and so there was an error message.

Error messages are often cryptic to the untrained eye. This one means your braces are not balanced.

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