Thursday, April 30, 2009

Note to self: Serial.baud(x) vs Serial.baud(var)

It seems that in one of the revisions of the Arduino IDE I was able to do something like this:

int baud = 57600;

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

void loop() {
// do stuff here
}


The idea with having the baud rate defined as a variable is that it can be changed quite easily between debugging via a USB serial connection and testing / using via a MIDI connection. However, this no longer seems to work as the serial function does not recognise any data. Instead, this has to be written as:


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

void loop() {
// do stuff here
}

2 comments:

Gabriel M. Schuyler said...

I think you could #define BAUD 57600 at the top of your sketch and then Serial.begin(BAUD); in setup would act like you want it to.

Anonymous said...

Try

#define __BAUD 57600

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

Should work with all versions of the arduino software