Library for interfacing to Nokia 5110 LCD display (as found on the SparkFun website).
Fork of N5110 by
Revision 44:cd9bc22f656d, committed 2017-05-03
- Comitter:
- JackCripps
- Date:
- Wed May 03 12:52:37 2017 +0000
- Parent:
- 43:c2598020fcac
- Commit message:
- Added getBrightness function and flashing string function
Changed in this revision
diff -r c2598020fcac -r cd9bc22f656d Bitmap.cpp --- a/Bitmap.cpp Tue Mar 21 11:46:14 2017 +0000 +++ b/Bitmap.cpp Wed May 03 12:52:37 2017 +0000 @@ -90,7 +90,11 @@ // Find the required value of the pixel at the given location within // the bitmap data and then write it to the LCD screen int pixel = get_pixel(bitmap_row, bitmap_col); - lcd.setPixel(screen_col, screen_row, pixel); + // Since 2 in my bitmaps dictates transaprent pixel, do not set pixel + // on lcd if the pixel value is 2 + if (pixel != 2) { + lcd.setPixel(screen_col, screen_row, pixel); + } } } } \ No newline at end of file
diff -r c2598020fcac -r cd9bc22f656d Bitmap.h --- a/Bitmap.h Tue Mar 21 11:46:14 2017 +0000 +++ b/Bitmap.h Wed May 03 12:52:37 2017 +0000 @@ -10,9 +10,11 @@ * @brief A black & white bitmap that can be rendered on an N5110 screen * @author Alex Valavanis <a.valavanis@leeds.ac.uk> * + * @detail Slight modification by Jack Cripps to deal with transparency issue + * * @code // First declare the pixel map data using '1' for black, - // or '0' for white pixels + // or '0' for white pixels, or '2' for transparent static int sprite_data[] = { 0,0,1,0,0, 0,1,1,1,0, @@ -40,7 +42,7 @@ private: /** * @brief The contents of the drawing, with pixels stored in row-major order - * @details '1' represents a black pixel; '0' represents white + * @details '1' represents a black pixel; '0' represents white, '2' transparent */ std::vector<int> _contents;
diff -r c2598020fcac -r cd9bc22f656d N5110.cpp --- a/N5110.cpp Tue Mar 21 11:46:14 2017 +0000 +++ b/N5110.cpp Wed May 03 12:52:37 2017 +0000 @@ -75,6 +75,10 @@ clearRAM(); // RAM is undefined at power-up so clear clear(); // clear buffer setBrightness(0.5); + + // Initialising the frame count variable to 0 + _frameCount = 0; + _textTransparency = 0; } // sets normal video mode (black on white) @@ -132,6 +136,13 @@ _led->write(brightness); } +// function to get led brightness +float N5110::getBrightness() +{ + // Returns value between 0.0 and 1.0; + return _led->read(); +} + // pulse the active low reset line void N5110::reset() @@ -302,6 +313,24 @@ } } +void N5110::printFlashingString(const char *str, + unsigned int const x, + unsigned int const y, + unsigned int const framesBeforeUpdate) +{ + if (++_frameCount == framesBeforeUpdate) + { + _frameCount = 0; + _textTransparency = !_textTransparency; + + } + + if (!_textTransparency) + { + this->printString(str, x, y); + } +} + // function to clear the screen buffer void N5110::clear() {
diff -r c2598020fcac -r cd9bc22f656d N5110.h --- a/N5110.h Tue Mar 21 11:46:14 2017 +0000 +++ b/N5110.h Wed May 03 12:52:37 2017 +0000 @@ -294,6 +294,13 @@ * @param brightness - float in range 0.0 to 1.0 */ void setBrightness(float const brightness); + + /** get Brightness + * + * Gets brightness of LED backlight + * @returns float in range 0.0 to 1.0 + */ + float getBrightness(); /** Print String * @@ -304,6 +311,18 @@ void printString(char const *str, unsigned int const x, unsigned int const y); + + /** Print flashing string + * + * Prints a string of characters to the string buffer. Flashes at the frame interval specified + * @param x the coloumn number + * @param y the row number + * @param framesBeforeUpdate number of frames before changing from nothing to text + */ + void printFlashingString(char const *str, + unsigned int const x, + unsigned int const y, + unsigned int const framesBeforeUpdate); /** Print Character * @@ -450,6 +469,8 @@ void clearRAM(); void sendCommand(unsigned char command); void sendData(unsigned char data); + int _frameCount; + bool _textTransparency; }; const unsigned char font5x7[480] = {