Error with enum in arduino IDE

Hello!

I am having issues with two lines of code

enum mode_t {RELATIVE, ABSOLUTE};

mode_t theMode = RELATIVE;

These work on my arduino leonardo board but not XIAO ble SENSE board not running on the mbed plateform but non-embed. Does anyone have a work around?

Hi there,
I have lurked on the thread at Arduino forum,
2 things:

I still don’t get the serial prompt asking Absolute or Relative prompt in serial, but knowing the question and typing A or R does in fact work and switch modes on the fly!

Thank you very much for this awesome solution in nearly 1 shot! Would you mind directing me on how I can convert this to a button change and preferably as an interrupt?

Xiao uses the DO and D1 as possible strapping pins. so any hard ware connections should be verified they won’t cause BL mode and serial port issues.

I don’t see any delay that is required for you to see the prompt after reset.
It should be this,

ezButton someButton (3, INPUT_PULLUP);

void setup() {
  Serial.begin(9600);  // ADD THIS AND TRY AGAIN.
delay (2000);
  Serial.println("Hello ezButton World!\n");

  someButton.setDebounceTime(50);
}

HTH
GL :slight_smile: PJ

FWIW , You can generate an Interrupt on receive character in serial port. So …FYI
:v:

Thank you! I wasn’t aware of d0 and d1 acted as such. I figured stay away from pin 6,7 Tx/rx?

The delay worked! How do you add interrupt on incoming serial or is that built in?

I realized the error with enum issue stated initially. It appears those variables being used so I just renamed them.

Thank you!!

Hi there,
it something like this,

void setup(){
 Serial.begin(9600);  
  pinMode(7, INPUT);      // Make pin 7 RXD an input
   
    // attach our interrupt pin to it's ISR
    attachInterrupt(0, recISR, CHANGE);
    // we need to call this to enable interrupts
    interrupts();
}

// The interrupt hardware calls this when we hit our left bumper
void recISR(){

  //  rec = 1;
     Serial.println("interrupt!"); 
 

}

this is only one way , there are several.
BTW , the solution was what I posted not your own :face_with_hand_over_mouth: post… LOL
HTH
GL :slight_smile: PJ
:v:

basically it’s the pin changing from the data arriving the Isr sets a flag and the loop reads the port REC data.

You are awesome. Thank you for the code and explanation!

1 Like