I ran into an odd problem when trying to compile a sketch for the Arduino Zero/M0 containing an enum definition. The Arduino IDE compiles the sketch successfully, while Visual Micro fails.
I simplified the sketch to only contain the problem:
enum class BoardState
{
Initializing = 0,
PowerOn,
Failed,
None
};
void setup() {}
void loop() {}
void setLed(BoardState state)
{
// Do stuff here
}
Visual Micro fails with the following error message:
TestSketch.ino: 4:13: error: variable or field 'setLed' declared void
PowerOn
TestSketch.ino: 4:13: error: 'BoardState' was not declared in this scope
Error compiling project sources
Build failed for project 'TestSketch'
Switching between 'Visual Micro (No IDE)' and 'Arduino 1.6/1.8' makes no difference.
The problem seems to be the order of where stuff is put in the generated sketch cpp file.
Arduino IDE:
#include <Arduino.h>
#line 1 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
#line 1 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
enum class BoardState
{
Initializing = 0,
PowerOn,
Failed,
None
};
#line 9 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
void setup();
#line 14 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
void loop();
#line 19 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
void setLed(BoardState state);
#line 9 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
void setLed(BoardState state)
{}
Visual Micro:
#include <arduino.h>
#line 1 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
#line 1 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
//
//
void setLed(BoardState state);
#line 1 "C:\\Users\\jonny\\Documents\\Arduino\\TestSketch\\TestSketch.ino"
enum class BoardState
{
Initializing = 0,
PowerOn,
Failed,
None
};
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
void setLed(BoardState state)
{}