arduino-libraries / LiquidCrystal

Liquid Crystal Library for Arduino
http://arduino.cc/
246 stars 169 forks source link

init() needlessly calls begin() #69

Open iflyhigh opened 1 year ago

iflyhigh commented 1 year ago

init() function for some reason calls begin(16, 1) without any good reason for doing so. init() is normally called from LiquidCrystal constructor and begin() needs to be called from user program before any other code. Current code actually performs double LCD initialization which appears to be harmless but unneeded/time consuming.

https://github.com/arduino-libraries/LiquidCrystal/blob/db84824c8dff0cca3c689fcb8f09252747e574d9/src/LiquidCrystal.cpp#L70-L76

6v6gt-duino commented 1 year ago

This is also raised in issue #11 and issue #41 (currently both open) It is not harmless because it causes a failure on some platforms. It is generally incorrect to include, in the constructor, functions which depend on the Arduino run time system being ready, since the object instantiation happens long before that. The unwanted call of begin( 16, 1) has the effect of calling delayMicroseconds() from the constructor and the impact of that depends on the platform. On AVR, delayMicroseconds() falls through immediately if timer0 is not (yet) running so it may appear to work although useless because the timings for the initialisation sequence as specified in the HD44780 data sheet are ignored.