Using the IDE on OSX, the following code :
#include <LiquidCrystal.h>
// initialize the display
const int rs = 7, en = 8, d4 = 9, d5 = 10, d6 = 11, d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Setup LCD
lcd.begin(16, 2);
void setup() {
}
void loop() {
}
Produces an error
references:8:1: error: 'lcd' does not name a type
lcd.begin(16, 2);
^~~
exit status 1
'lcd' does not name a type
I am just interested in why the lcd.begin() call must be within setup() function in order to compile without errors.