ENUM warnings and errors

Sorry, I've removed it. I guess it's inappropriate. Have fun y'all.

Four states plus LEN which we’ll cheat and use for modulo math in a rollover loop.

That’s not cheating. That’s quite common.

Any ideas?

The compiler was warning that you are trying to implicitly convert one type to another, when the types are not the same size. An enum rarely has more than 255 values, so the underlying type is usually byte. Storing an int an a byte COULD result in loss of data.

By using the explicit cast, you are telling the compiler “Leave me alone. I want to shoot myself in the foot”.

The CodeBlocks issue is not an Arduino problem.

DKWatson:
drawer_state = (state)((drawer_state + 1) % LEN);

error: 'state' undeclared (first use in this function)

For best compatibility, I think the statement should be:

    drawer_state = (enum state)( ((int)drawer_state + 1) % (int)LEN );

Yours,
TonyWilk

PaulS

I use Code::Blocks as an editor and to compile with AVR-GCC before uploading with avrdude to Arduino. Does that mean that this forum will only accept Arduino issues involving the IDE?

DKWatson:
PaulS

I use Code::Blocks as an editor and to compile with AVR-GCC before uploading with avrdude to Arduino. Does that mean that this forum will only accept Arduino issues involving the IDE?

What it means is that you have a Code::Blocks issue which is best addressed on a different forum. Perhaps a gun club.

enum State {
  A,
  B,
  C,
  STATES_MAX
};

State state = A;

void setup() {
  Serial.begin(9600);
}

void loop() {
  switch (state) {
    case A:
      Serial.println(F("State = A"));
      break;
    case B:
      Serial.println(F("State = B"));
      break;
    case C:
      Serial.println(F("State = C"));
      break;
  }
  int mode = static_cast<int>(state);
  state = static_cast<State>(++mode % STATES_MAX);
  delay(1000);
}

DKWatson:
I use Code::Blocks as an editor and to compile with AVR-GCC before uploading with avrdude to Arduino. Does that mean that this forum will only accept Arduino issues involving the IDE?

Snide comments aside, it means you're asking a bunch of people who don't use the tool you're having a problem with - so you're not likely to reach someone who knows how to help.

I'm here like... all the time... and I think I hear codeblocks mentioned a few times a year, and I can't recall any of them getting an answer that helps.