This code doesn't compile - I get:
test_prog:16:13: error: variable or field 'LCDcmd' declared void
void LCDcmd(LCDcmd_t cmd, int row, int column) {
test_prog:16:13: error: 'LCDcmd_t' was not declared in this scope
const int MY_LED = 8;
void setup() {
Serial.begin(9600);
delay(1000);
pinMode(MY_LED, OUTPUT);
}
enum LCDcmd_t {
lcd_clear,lcd_home,lcd_gotoxy,lcd_cursor_off,lcd_cursor_on
};
void LCDcmd(LCDcmd_t cmd, int row, int column) {
// For NHD brand serial displays
// column 0..15, row 0..1
switch(cmd) {
case lcd_clear:
Serial.write(0xFE); Serial.write(0x51); delay(500);
break;
case lcd_home:
Serial.write(0xFE); Serial.write(0x46); delay(100);
break;
case lcd_gotoxy:
Serial.write(0xFE); Serial.write(0x45); Serial.write(byte(row * 0x40 + column));
delay(100);
break;
case lcd_cursor_off:
Serial.write(0xFE); Serial.write(0x4C); // blinking cursor off
delay(50);
Serial.write(0xFE); Serial.write(0x48); // underline cursor off
delay(50);
break;
case lcd_cursor_on:
Serial.write(0xFE); Serial.write(0x4B); // blinking cursor on
delay(50);
break;
}
} //end LCDcmd;
void loop () {
digitalWrite(MY_LED, true);
delay(500);
digitalWrite(MY_LED, false);
delay(500);
}
However, if I add the function prototype for LCDcmd before the actual LCDcmd function, it compiles fine.
const int MY_LED = 8;
void setup() {
Serial.begin(9600);
delay(1000);
pinMode(MY_LED, OUTPUT);
}
enum LCDcmd_t {
lcd_clear,lcd_home,lcd_gotoxy,lcd_cursor_off,lcd_cursor_on
};
void LCDcmd(LCDcmd_t cmd, int row, int column);
void LCDcmd(LCDcmd_t cmd, int row, int column) {
// For NHD brand serial displays
// column 0..15, row 0..1
switch(cmd) {
case lcd_clear:
Serial.write(0xFE); Serial.write(0x51); delay(500);
break;
case lcd_home:
Serial.write(0xFE); Serial.write(0x46); delay(100);
break;
case lcd_gotoxy:
Serial.write(0xFE); Serial.write(0x45); Serial.write(byte(row * 0x40 + column));
delay(100);
break;
case lcd_cursor_off:
Serial.write(0xFE); Serial.write(0x4C); // blinking cursor off
delay(50);
Serial.write(0xFE); Serial.write(0x48); // underline cursor off
delay(50);
break;
case lcd_cursor_on:
Serial.write(0xFE); Serial.write(0x4B); // blinking cursor on
delay(50);
break;
}
} //end LCDcmd;
void loop () {
digitalWrite(MY_LED, true);
delay(500);
digitalWrite(MY_LED, false);
delay(500);
}
What's going on? Looks to me like the first version should be fine, with the C++ method of using enum.