use button to control LCD backlight

Started by mzv72m, January 20, 2016, 07:43:43 PM

mzv72m

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.
Dan

Felix

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.

peckcj

Sounds easy as pie...just need to find the time to learn how to do it. HA!! ;)

Felix

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 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);

mzv72m

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?
Dan

Felix

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); }

mzv72m

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.
Dan

Felix

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:

mzv72m

Dan

peckcj