LowPowerLab Forum

Software support => Pi Gateway => Topic started by: mzv72m on January 20, 2016, 07:43:43 PM

Title: use button to control LCD backlight
Post by: mzv72m on January 20, 2016, 07:43:43 PM
I have been trying to use one of the buttons to turn off/on the backlight, but I have not been able to just set the backlight to off.
Title: Re: use button to control LCD backlight
Post by: Felix on January 20, 2016, 08:13:21 PM
Ok so the 2 buttons are on A4 and A5 (R2), will pull down the pins when they are pressed.
The LED backlight is on D3.
Just setup the pin(s) as INPUT_PULLUP, read and debounce the button via software until they show as LOW value, then just flip the state of the LED.
Title: Re: use button to control LCD backlight
Post by: peckcj on January 20, 2016, 10:13:18 PM
Sounds easy as pie...just need to find the time to learn how to do it. HA!! ;)
Title: Re: use button to control LCD backlight
Post by: Felix on January 20, 2016, 11:20:59 PM
Maybe I'll find some time soon and do it myself :)
I still haven't decided what to do with the 2 buttons, that's a bigger HA!! .. or maybe a DOH!! ;)
Perhaps one can do the backlight and the other could flip through the last N received messages like I do it on the MotionOLEDMote.
By the way the MightyHat sketch (https://github.com/LowPowerLab/RFM69/blob/master/Examples/MightyHat/MightyHat.ino) already has an example of how to read/debounce a button attached to A2 (the power button), so it could be a good start to look at.

Look for this line, then what it does with BUTTON:
pinMode(BUTTON, INPUT_PULLUP);
Title: Re: use button to control LCD backlight
Post by: mzv72m on January 21, 2016, 11:51:55 AM
Quote from another topic that mentions the LCD.
Quote from: Felix on January 21, 2016, 11:17:31 AM
Ah, now I remember I looked at your sketch and I saw you used the adafruit lib for 5110, but then I forgot ;)
I was using that lib also in initial testing but it's too slow and bulky and uses too much memory, and is very limited compared to u8glib...
You can control the brightness by using a PWM pin, then use AnalogWrite(PWMPIN, 0..255) to alter the brightness.

So is this what you are doing in the MightyHat sketch?
Title: Re: use button to control LCD backlight
Post by: Felix on January 21, 2016, 04:02:46 PM
Quote from: mzv72m on January 21, 2016, 11:51:55 AM
So is this what you are doing in the MightyHat sketch?

Not really, right now I just turn it ON/OFF by calling this:

#define LCD_BACKLIGHT(x) { if (x) analogWrite(PIN_LCD_LIGHT, 100); else analogWrite(PIN_LCD_LIGHT, 0); }
Title: Re: use button to control LCD backlight
Post by: mzv72m on January 21, 2016, 10:20:26 PM
That is what I thought that section of code was doing.  Just only setting the on level to 100.

I need to do some more testing.  So far I have been unable to change the state of the backlight.
Title: Re: use button to control LCD backlight
Post by: Felix on January 22, 2016, 03:32:20 PM
Ok check out the latest version of the sketch, I implemented functions for the 2 buttons:

- BTN1 (top, A4) - backlight control, this flips through from 0 to 100% in 5 levels
- BTN2 (bottom, A5) - message history, 10 messages memory (uses RAM), this browses through past messages showing the data and RSSI

MISC other changes:
- shows system uptime in sec/min
- shows free RAM

DEMO:
Title: Re: use button to control LCD backlight
Post by: mzv72m on January 22, 2016, 07:30:23 PM
Very cool.

Thanks Felix.
Title: Re: use button to control LCD backlight
Post by: peckcj on January 22, 2016, 09:26:14 PM
Awesome!!! Thanks!!!
  ;D ;D ;D ;D ;D