diff --git a/rpi/lcd-screen/lcd.py b/rpi/lcd-screen/grove_rgb_lcd.py similarity index 53% rename from rpi/lcd-screen/lcd.py rename to rpi/lcd-screen/grove_rgb_lcd.py index ddf95dda..4283f69d 100644 --- a/rpi/lcd-screen/lcd.py +++ b/rpi/lcd-screen/grove_rgb_lcd.py @@ -1,6 +1,26 @@ -import time,sys -from grove_rgb_lcd import lcd +#!/usr/bin/env python +# +# GrovePi Example for using the Grove - LCD RGB Backlight (http://www.seeedstudio.com/wiki/Grove_-_LCD_RGB_Backlight) +# +# The GrovePi connects the Raspberry Pi and Grove sensors. You can learn more about GrovePi here: http://www.dexterindustries.com/GrovePi +# +# Have a question about this example? Ask on the forums here: http://forum.dexterindustries.com/c/grovepi +# +# History +# ------------------------------------------------ +# Author Date Comments +# Initial Authoring +# Karan 7 Jan 16 Library updated to add a function to update the text without erasing the screen +# Released under the MIT license (http://choosealicense.com/licenses/mit/). +# For more information see https://github.com/DexterInd/GrovePi/blob/master/LICENSE +# +# NOTE: +# Just supports setting the backlight colour, and +# putting a single string of text onto the display +# Doesn't support anything clever, cursors or anything + +import time,sys if sys.platform == 'uwp': import winrt_smbus as smbus @@ -75,15 +95,28 @@ def setText_norefresh(text): count += 1 bus.write_byte_data(DISPLAY_TEXT_ADDR,0x40,ord(c)) +# Create a custom character (from array of row patterns) +def create_char(location, pattern): + """ + Writes a bit pattern to LCD CGRAM + + Arguments: + location -- integer, one of 8 slots (0-7) + pattern -- byte array containing the bit pattern, like as found at + https://omerk.github.io/lcdchargen/ + """ + location &= 0x07 # Make sure location is 0-7 + textCommand(0x40 | (location << 3)) + bus.write_i2c_block_data(DISPLAY_TEXT_ADDR, 0x40, pattern) + # example code if __name__=="__main__": - setRGB(255, 255, 255) - # Total time in seconds - total_seconds = 5 * 60 - - while total_seconds >= 0: - minutes = total_seconds // 60 - seconds = total_seconds % 60 - setText(f"{minutes:02d}:{seconds:02d}") - time.sleep(1) - total_seconds -= 1 \ No newline at end of file + setText("Hello world\nThis is an LCD test") + setRGB(0,128,64) + time.sleep(2) + for c in range(0,255): + setText_norefresh("Going to sleep in {}...".format(str(c))) + setRGB(c,255-c,0) + time.sleep(0.1) + setRGB(0,255,0) + setText("Bye bye, this should wrap onto next line") \ No newline at end of file