Here's a fix for anyone having trouble dimming the LCD backlight using the New LiquidCrystal library with a parallel connection. The preprocessor code is incorrect and always uses the "#else" clause.
Also note that the HelloWorld_4bit example incorrectly tries to use the backlight() method before the begin() method.
diff -uNr orig/Newliquidcrystal_1.3.5/LiquidCrystal.cpp Newliquidcrystal_1.3.5/LiquidCrystal.cpp
--- orig/Newliquidcrystal_1.3.5/LiquidCrystal.cpp 2017-11-26 22:42:28.000000000 -0500
+++ Newliquidcrystal_1.3.5/LiquidCrystal.cpp 2019-03-06 23:02:27.000000000 -0500
@@ -174,9 +174,9 @@
// 1.5x Arduino and above has a macro to check for PWM capability
// on a pin.
// ---------------------------------------------------
-#if digitalPinHasPWM
+#if defined(digitalPinHasPWM)
if(digitalPinHasPWM(_backlightPin))
-#elif digitalPinToTimer
+#elif defined(digitalPinToTimer)
// On older 1.x Arduino have to check using hack
if(digitalPinToTimer(_backlightPin) != NOT_ON_TIMER)
#else
The "New LiquidCrystal library" is actually quite old.
When the author FM first introduced it I asked him what he was going to name it's successor. I don't recall that he had an answer.
A better solution would be to use the HD44780 library.
Don
I was directly involved with the dimming code in the new LiquidCrystal library and figuring out the macros to auto determine what is possible.
I'm not sure how that ifdef issue happened.
I am no longer involved with that library code.
Here is what I used in the hd44780 library in the hd44780_pinIO i/o class:
// Check if backlight pin has PWM support
// The reason this has to be done is that Arduino analogWrite()
// sets a pin to LOW if there is no PWM support and the PWM value is
// less than half of maximum. This is not desired behavior.
// The desired behavior is that if dimming is not supported, then the
// output is full on until the PWM value is zero to indicate "off".
// So we have to bypass the goofy code in analogWrite()
// by detecting if the pin supports PWM and controlling the output manually
// when no PWM is available.
#if defined(digitalPinHasPWM)
// Newer 1.5x Arduino has a macro to check for PWM capability on a pin
if(digitalPinHasPWM(_bl))
#elif defined(digitalPinToTimer)
// On 1.x Arduino have to check differently
if(digitalPinToTimer(_bl) != NOT_ON_TIMER)
#else
if(0) // no way to tell so assume no PWM
#endif
Jay_Kulpinski,
If you want this fixed, my suggestion would be to either create an issue or a pull request to the new LiquidCrystal bitbucket repository. https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
It looks like it is being worked on right now and several updates, including fixing the long oustanding licensing issues, are in progress in preparation of a new release so it looks like a good time to put in issues or pull requests for fixes.
Alternatively, you could switch to the hd44780 library.
--- bill