uLCD-144-G2 Screen Saver Functions

Overview

The objective of the screensaver() function is to prevent pixels on the uLCD screen from burning out due to being static to only one color. The pixels on the screen are written with various colors to refresh them based on the idleness of user inputs. Idleness is detected by checking a global counter variable to see if its value has reached a specified threshold. Screensaver mode will activate when the program sensed as being idle, and will deactivate if the counter variable is reset back to 0. The counter must be reset to 0 whenever a user inputs actions or commands.

uLCD-144-G2 Pinout

Pin numberuLCD pinsmbed pins
15VVU
2GndGnd
3RXP9= TX
4TXP10= RX
5ResetP11= Reset

screensaver() Function Snippet

Include following Snippet and Libraries in code

//Programs that use this function must reset counter variable in its button or input callback functions. 
//See 'Example Program' for more information if necessary on the wiki page:
//https://developer.mbed.org/users/dtravisano3/notebook/ulcdscreensaver/

#include "mbed.h"
#include "uLCD_4DGL.h"
#include "rtos.h"

uLCD_4DGL uLCD(p9,p10,p11);     //serial tx, serial rx, reset pin;

int volatile counter=0;         //global counter variable

int color[] = {RED,BLUE,GREEN}; //color to be written to screen

Mutex DAmu;          // rtos mutex initialization

void screensaver(void const *args)
{
    //pc.printf("/n %d", counter);
    while(counter!=0) {
        uLCD.cls();
        for(int i=0; i<(128)&&counter!=0; i++) {       //cycle through all 128x128 pixels of uLCD
            for(int k=0; (k<128)&&counter!=0; k++) {
                DAmu.lock();                           //use mutex to prevent simultaneous access of screen
                uLCD.pixel(k,i,color[rand()%3]);       //randomizes color to be written to pixel
                DAmu.unlock();
            }
        }
        uLCD.cls();
        Thread::wait(1000);
    }
}

Libraries

uLCD-144-G2:

Import library4DGL-uLCD-SE

Fork of 4DGL lib for uLCD-144-G2. Different command values needed. See https://mbed.org/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ for instructions and demo code.

mbed-rtos:

Import librarymbed-rtos

Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.

Example Program

Example code that implements uLCD ScreenSaver function with simple uLCD program. Includes use of PullDown Pushbuttons (or Joystick module) on mbed pins 13-17 and PinDetect library for detecting user idleness.

https://developer.mbed.org/users/dtravisano3/code/ScreenSaver/

Import programScreenSaver

uLCD-144-G2 Screen Saver Example Code

Notes and Issues

Anything on screen before entering screensaver mode must be redrawn to screen by the user program. screensave() and screenrecover() functions are included in the Example Program, but are not used due to limited RAM on the mbed. An external storage device such as an SD card would be required for saving screenshots.

Other Links

uLCD-144-G2 Wiki Page: https://developer.mbed.org/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/

RTOS and Mutex Wiki Page: https://developer.mbed.org/handbook/RTOS

PinDetect Wiki Page (used in example code): https://developer.mbed.org/users/AjK/code/PinDetect/docs/cb3afc45028b/classAjK_1_1PinDetect.html


Please log in to post comments.