Given the following enums
enum RelayState { RELAY_OFF = HIGH, RELAY_ON = LOW };
enum class CrossingZoneState: uint8_t {
CROSSINGZONE_CLEAR = 0, // no train in crossing area, also initialized state
CROSSINGZONE_OCCUPIED = 1, // train detected by the entry sensor
CROSSINGZONE_EXITING = 2 // train detected by the exit sensor, when sensor clears, state= Clear
};
Where RELAY_OFF = HIGH, HIGH is #define HIGH 0x1 which I assume is a C++/Arduino constant? because I didn't define it. And RELAY_ON = LOW, LOW is 0x0
in the following function I get the error that follows.
CrossingZoneState CheckEntrySensor(uint8_t esp) {
//esp, short for entry sensor pin
if (digitalRead(esp) == HIGH)
{
state = CrossingZoneState::CROSSINGZONE_CLEAR;
return state;
}
else if (digitalRead(esp) == LOW)
{
state = CrossingZoneState::CROSSINGZONE_OCCUPIED;
return state;
}
// if the digital read errs, return the current state so it re-runs
return state;
};
boolean throwRelayAndCheckStatus(uint8_t relayNumber, RelayState relayState) {
int testInt = 0;
if (relayState == RelayState::RELAY_OFF)
{
testInt = 1;
}
digitalWrite(relayNumber, relayState);
if (digitalRead(relayNumber) == testInt) {
return true;
};
return false;
};
I tried having RelayState be an enum class as well but was getting similar type errors. Here is the error from VS2015 with the code shown above.
Compiling debug version of 'ModelRRXingStateMachine' for 'Arduino/Genuino Uno' ModelRRXingStateMachine.ino:11:55: error: 'RelayState' has not been declared :boolean throwRelayAndCheckStatus(uint8_t relayNumber, RelayState relayState) ModelRRXingStateMachine.ino:2:1: error: 'CrossingZoneState' does not name a type :CrossingZoneState CheckEntrySensor(byte esp) Error compiling project sources
I'm not a professional programmer and am new to C++, usually writing in C# or VB.Net so I'm not sure what the compiler is looking for here, both enums are declared and one is declared with a type. Also, the VS code editor is showing no errors, the errors shown above show up in the error window when I try to build.