summaryrefslogtreecommitdiff
path: root/Adafruit_Python_CharLCD/examples
diff options
context:
space:
mode:
authorCody Hiar <codyfh@gmail.com>2018-05-12 21:42:50 -0600
committerCody Hiar <codyfh@gmail.com>2018-05-12 21:42:50 -0600
commit83fd91dd6af67b1656a09127971153fa699b7372 (patch)
tree46b919ab27c2782e186bcdeb728cace9824c32fe /Adafruit_Python_CharLCD/examples
parent83bb8e8a54c66ae42461819506990207df7549c1 (diff)
LCD Screen Working, Adding adafruit dependancies
Diffstat (limited to 'Adafruit_Python_CharLCD/examples')
-rwxr-xr-xAdafruit_Python_CharLCD/examples/char_lcd.py84
-rwxr-xr-xAdafruit_Python_CharLCD/examples/char_lcd_backpack.py63
-rwxr-xr-xAdafruit_Python_CharLCD/examples/char_lcd_mcp.py85
-rwxr-xr-xAdafruit_Python_CharLCD/examples/char_lcd_plate.py75
-rwxr-xr-xAdafruit_Python_CharLCD/examples/char_lcd_rgb.py76
-rwxr-xr-xAdafruit_Python_CharLCD/examples/char_lcd_rgb_pwm.py129
6 files changed, 512 insertions, 0 deletions
diff --git a/Adafruit_Python_CharLCD/examples/char_lcd.py b/Adafruit_Python_CharLCD/examples/char_lcd.py
new file mode 100755
index 0000000..a7e017e
--- /dev/null
+++ b/Adafruit_Python_CharLCD/examples/char_lcd.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python
+# Example using a character LCD connected to a Raspberry Pi or BeagleBone Black.
+import time
+
+import Adafruit_CharLCD as LCD
+
+
+# Raspberry Pi pin configuration:
+lcd_rs = 27 # Note this might need to be changed to 21 for older revision Pi's.
+lcd_en = 22
+lcd_d4 = 25
+lcd_d5 = 24
+lcd_d6 = 23
+lcd_d7 = 18
+lcd_backlight = 4
+
+# BeagleBone Black configuration:
+# lcd_rs = 'P8_8'
+# lcd_en = 'P8_10'
+# lcd_d4 = 'P8_18'
+# lcd_d5 = 'P8_16'
+# lcd_d6 = 'P8_14'
+# lcd_d7 = 'P8_12'
+# lcd_backlight = 'P8_7'
+
+# Define LCD column and row size for 16x2 LCD.
+lcd_columns = 16
+lcd_rows = 2
+
+# Alternatively specify a 20x4 LCD.
+# lcd_columns = 20
+# lcd_rows = 4
+
+# Initialize the LCD using the pins above.
+lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
+ lcd_columns, lcd_rows, lcd_backlight)
+
+# Print a two line message
+lcd.message('Hello\nworld!')
+
+# Wait 5 seconds
+time.sleep(5.0)
+
+# Demo showing the cursor.
+lcd.clear()
+lcd.show_cursor(True)
+lcd.message('Show cursor')
+
+time.sleep(5.0)
+
+# Demo showing the blinking cursor.
+lcd.clear()
+lcd.blink(True)
+lcd.message('Blink cursor')
+
+time.sleep(5.0)
+
+# Stop blinking and showing cursor.
+lcd.show_cursor(False)
+lcd.blink(False)
+
+# Demo scrolling message right/left.
+lcd.clear()
+message = 'Scroll'
+lcd.message(message)
+for i in range(lcd_columns-len(message)):
+ time.sleep(0.5)
+ lcd.move_right()
+for i in range(lcd_columns-len(message)):
+ time.sleep(0.5)
+ lcd.move_left()
+
+# Demo turning backlight off and on.
+lcd.clear()
+lcd.message('Flash backlight\nin 5 seconds...')
+time.sleep(5.0)
+# Turn backlight off.
+lcd.set_backlight(0)
+time.sleep(2.0)
+# Change message.
+lcd.clear()
+lcd.message('Goodbye!')
+# Turn backlight on.
+lcd.set_backlight(1)
diff --git a/Adafruit_Python_CharLCD/examples/char_lcd_backpack.py b/Adafruit_Python_CharLCD/examples/char_lcd_backpack.py
new file mode 100755
index 0000000..3c24949
--- /dev/null
+++ b/Adafruit_Python_CharLCD/examples/char_lcd_backpack.py
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+# Example using a character LCD backpack.
+import time
+
+import Adafruit_CharLCD as LCD
+
+# Define LCD column and row size for 16x2 LCD.
+lcd_columns = 16
+lcd_rows = 2
+
+# Initialize the LCD using the pins
+lcd = LCD.Adafruit_CharLCDBackpack()
+
+# Turn backlight on
+lcd.set_backlight(0)
+
+# Print a two line message
+lcd.message('Hello\nworld!')
+
+# Wait 5 seconds
+time.sleep(5.0)
+
+# Demo showing the cursor.
+lcd.clear()
+lcd.show_cursor(True)
+lcd.message('Show cursor')
+
+time.sleep(5.0)
+
+# Demo showing the blinking cursor.
+lcd.clear()
+lcd.blink(True)
+lcd.message('Blink cursor')
+
+time.sleep(5.0)
+
+# Stop blinking and showing cursor.
+lcd.show_cursor(False)
+lcd.blink(False)
+
+# Demo scrolling message right/left.
+lcd.clear()
+message = 'Scroll'
+lcd.message(message)
+for i in range(lcd_columns-len(message)):
+ time.sleep(0.5)
+ lcd.move_right()
+for i in range(lcd_columns-len(message)):
+ time.sleep(0.5)
+ lcd.move_left()
+
+# Demo turning backlight off and on.
+lcd.clear()
+lcd.message('Flash backlight\nin 5 seconds...')
+time.sleep(5.0)
+# Turn backlight off.
+lcd.set_backlight(1)
+time.sleep(2.0)
+# Change message.
+lcd.clear()
+lcd.message('Goodbye!')
+# Turn backlight on.
+lcd.set_backlight(0) \ No newline at end of file
diff --git a/Adafruit_Python_CharLCD/examples/char_lcd_mcp.py b/Adafruit_Python_CharLCD/examples/char_lcd_mcp.py
new file mode 100755
index 0000000..58b8d70
--- /dev/null
+++ b/Adafruit_Python_CharLCD/examples/char_lcd_mcp.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python
+# Example using an RGB character LCD connected to an MCP23017 GPIO extender.
+import time
+
+import Adafruit_CharLCD as LCD
+import Adafruit_GPIO.MCP230xx as MCP
+
+
+# Define MCP pins connected to the LCD.
+lcd_rs = 0
+lcd_en = 1
+lcd_d4 = 2
+lcd_d5 = 3
+lcd_d6 = 4
+lcd_d7 = 5
+lcd_red = 6
+lcd_green = 7
+lcd_blue = 8
+
+# Define LCD column and row size for 16x2 LCD.
+lcd_columns = 16
+lcd_rows = 2
+
+# Alternatively specify a 20x4 LCD.
+# lcd_columns = 20
+# lcd_rows = 4
+
+# Initialize MCP23017 device using its default 0x20 I2C address.
+gpio = MCP.MCP23017()
+
+# Alternatively you can initialize the MCP device on another I2C address or bus.
+# gpio = MCP.MCP23017(0x24, busnum=1)
+
+# Initialize the LCD using the pins
+lcd = LCD.Adafruit_RGBCharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
+ lcd_columns, lcd_rows, lcd_red, lcd_green, lcd_blue,
+ gpio=gpio)
+
+# Print a two line message
+lcd.message('Hello\nworld!')
+
+# Wait 5 seconds
+time.sleep(5.0)
+
+# Demo showing the cursor.
+lcd.clear()
+lcd.show_cursor(True)
+lcd.message('Show cursor')
+
+time.sleep(5.0)
+
+# Demo showing the blinking cursor.
+lcd.clear()
+lcd.blink(True)
+lcd.message('Blink cursor')
+
+time.sleep(5.0)
+
+# Stop blinking and showing cursor.
+lcd.show_cursor(False)
+lcd.blink(False)
+
+# Demo scrolling message right/left.
+lcd.clear()
+message = 'Scroll'
+lcd.message(message)
+for i in range(lcd_columns-len(message)):
+ time.sleep(0.5)
+ lcd.move_right()
+for i in range(lcd_columns-len(message)):
+ time.sleep(0.5)
+ lcd.move_left()
+
+# Demo turning backlight off and on.
+lcd.clear()
+lcd.message('Flash backlight\nin 5 seconds...')
+time.sleep(5.0)
+# Turn backlight off.
+lcd.set_backlight(0)
+time.sleep(2.0)
+# Change message.
+lcd.clear()
+lcd.message('Goodbye!')
+# Turn backlight on.
+lcd.set_backlight(1)
diff --git a/Adafruit_Python_CharLCD/examples/char_lcd_plate.py b/Adafruit_Python_CharLCD/examples/char_lcd_plate.py
new file mode 100755
index 0000000..be7ccdd
--- /dev/null
+++ b/Adafruit_Python_CharLCD/examples/char_lcd_plate.py
@@ -0,0 +1,75 @@
+#!/usr/bin/python
+# Example using a character LCD plate.
+import time
+
+import Adafruit_CharLCD as LCD
+
+
+# Initialize the LCD using the pins
+lcd = LCD.Adafruit_CharLCDPlate()
+
+# create some custom characters
+lcd.create_char(1, [2, 3, 2, 2, 14, 30, 12, 0])
+lcd.create_char(2, [0, 1, 3, 22, 28, 8, 0, 0])
+lcd.create_char(3, [0, 14, 21, 23, 17, 14, 0, 0])
+lcd.create_char(4, [31, 17, 10, 4, 10, 17, 31, 0])
+lcd.create_char(5, [8, 12, 10, 9, 10, 12, 8, 0])
+lcd.create_char(6, [2, 6, 10, 18, 10, 6, 2, 0])
+lcd.create_char(7, [31, 17, 21, 21, 21, 21, 17, 31])
+
+# Show some basic colors.
+lcd.set_color(1.0, 0.0, 0.0)
+lcd.clear()
+lcd.message('RED \x01')
+time.sleep(3.0)
+
+lcd.set_color(0.0, 1.0, 0.0)
+lcd.clear()
+lcd.message('GREEN \x02')
+time.sleep(3.0)
+
+lcd.set_color(0.0, 0.0, 1.0)
+lcd.clear()
+lcd.message('BLUE \x03')
+time.sleep(3.0)
+
+lcd.set_color(1.0, 1.0, 0.0)
+lcd.clear()
+lcd.message('YELLOW \x04')
+time.sleep(3.0)
+
+lcd.set_color(0.0, 1.0, 1.0)
+lcd.clear()
+lcd.message('CYAN \x05')
+time.sleep(3.0)
+
+lcd.set_color(1.0, 0.0, 1.0)
+lcd.clear()
+lcd.message('MAGENTA \x06')
+time.sleep(3.0)
+
+lcd.set_color(1.0, 1.0, 1.0)
+lcd.clear()
+lcd.message('WHITE \x07')
+time.sleep(3.0)
+
+# Show button state.
+lcd.clear()
+lcd.message('Press buttons...')
+
+# Make list of button value, text, and backlight color.
+buttons = ( (LCD.SELECT, 'Select', (1,1,1)),
+ (LCD.LEFT, 'Left' , (1,0,0)),
+ (LCD.UP, 'Up' , (0,0,1)),
+ (LCD.DOWN, 'Down' , (0,1,0)),
+ (LCD.RIGHT, 'Right' , (1,0,1)) )
+
+print('Press Ctrl-C to quit.')
+while True:
+ # Loop through each button and check if it is pressed.
+ for button in buttons:
+ if lcd.is_pressed(button[0]):
+ # Button is pressed, change the message and backlight.
+ lcd.clear()
+ lcd.message(button[1])
+ lcd.set_color(button[2][0], button[2][1], button[2][2])
diff --git a/Adafruit_Python_CharLCD/examples/char_lcd_rgb.py b/Adafruit_Python_CharLCD/examples/char_lcd_rgb.py
new file mode 100755
index 0000000..312a9e4
--- /dev/null
+++ b/Adafruit_Python_CharLCD/examples/char_lcd_rgb.py
@@ -0,0 +1,76 @@
+#!/usr/bin/python
+# Example using an RGB character LCD wired directly to Raspberry Pi or BeagleBone Black.
+import time
+
+import Adafruit_CharLCD as LCD
+
+
+# Raspberry Pi configuration:
+lcd_rs = 27 # Change this to pin 21 on older revision Raspberry Pi's
+lcd_en = 22
+lcd_d4 = 25
+lcd_d5 = 24
+lcd_d6 = 23
+lcd_d7 = 18
+lcd_red = 4
+lcd_green = 17
+lcd_blue = 7 # Pin 7 is CE1
+
+# BeagleBone Black configuration:
+# lcd_rs = 'P8_8'
+# lcd_en = 'P8_10'
+# lcd_d4 = 'P8_18'
+# lcd_d5 = 'P8_16'
+# lcd_d6 = 'P8_14'
+# lcd_d7 = 'P8_12'
+# lcd_red = 'P8_7'
+# lcd_green = 'P8_9'
+# lcd_blue = 'P8_11'
+
+# Define LCD column and row size for 16x2 LCD.
+lcd_columns = 16
+lcd_rows = 2
+
+# Alternatively specify a 20x4 LCD.
+# lcd_columns = 20
+# lcd_rows = 4
+
+# Initialize the LCD using the pins above.
+lcd = LCD.Adafruit_RGBCharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
+ lcd_columns, lcd_rows, lcd_red, lcd_green, lcd_blue)
+
+# Show some basic colors.
+lcd.set_color(1.0, 0.0, 0.0)
+lcd.clear()
+lcd.message('RED')
+time.sleep(3.0)
+
+lcd.set_color(0.0, 1.0, 0.0)
+lcd.clear()
+lcd.message('GREEN')
+time.sleep(3.0)
+
+lcd.set_color(0.0, 0.0, 1.0)
+lcd.clear()
+lcd.message('BLUE')
+time.sleep(3.0)
+
+lcd.set_color(1.0, 1.0, 0.0)
+lcd.clear()
+lcd.message('YELLOW')
+time.sleep(3.0)
+
+lcd.set_color(0.0, 1.0, 1.0)
+lcd.clear()
+lcd.message('CYAN')
+time.sleep(3.0)
+
+lcd.set_color(1.0, 0.0, 1.0)
+lcd.clear()
+lcd.message('MAGENTA')
+time.sleep(3.0)
+
+lcd.set_color(1.0, 1.0, 1.0)
+lcd.clear()
+lcd.message('WHITE')
+time.sleep(3.0)
diff --git a/Adafruit_Python_CharLCD/examples/char_lcd_rgb_pwm.py b/Adafruit_Python_CharLCD/examples/char_lcd_rgb_pwm.py
new file mode 100755
index 0000000..8f6fc2b
--- /dev/null
+++ b/Adafruit_Python_CharLCD/examples/char_lcd_rgb_pwm.py
@@ -0,0 +1,129 @@
+#!/usr/bin/python
+# Example using an RGB character LCD with PWM control of the backlight.
+import math
+import time
+
+import Adafruit_CharLCD as LCD
+
+
+def hsv_to_rgb(hsv):
+ """Converts a tuple of hue, saturation, value to a tuple of red, green blue.
+ Hue should be an angle from 0.0 to 359.0. Saturation and value should be a
+ value from 0.0 to 1.0, where saturation controls the intensity of the hue and
+ value controls the brightness.
+ """
+ # Algorithm adapted from http://www.cs.rit.edu/~ncs/color/t_convert.html
+ h, s, v = hsv
+ if s == 0:
+ return (v, v, v)
+ h /= 60.0
+ i = math.floor(h)
+ f = h-i
+ p = v*(1.0-s)
+ q = v*(1.0-s*f)
+ t = v*(1.0-s*(1.0-f))
+ if i == 0:
+ return (v, t, p)
+ elif i == 1:
+ return (q, v, p)
+ elif i == 2:
+ return (p, v, t)
+ elif i == 3:
+ return (p, q, v)
+ elif i == 4:
+ return (t, p, v)
+ else:
+ return (v, p, q)
+
+# Raspberry Pi configuration:
+lcd_rs = 27 # Change this to pin 21 on older revision Raspberry Pi's
+lcd_en = 22
+lcd_d4 = 25
+lcd_d5 = 24
+lcd_d6 = 23
+lcd_d7 = 18
+lcd_red = 4
+lcd_green = 17
+lcd_blue = 7 # Pin 7 is CE1
+
+# BeagleBone Black configuration:
+# lcd_rs = 'P8_8'
+# lcd_en = 'P8_10'
+# lcd_d4 = 'P8_18'
+# lcd_d5 = 'P8_16'
+# lcd_d6 = 'P8_14'
+# lcd_d7 = 'P8_12'
+# lcd_red = 'P9_16'
+# lcd_green = 'P9_14'
+# lcd_blue = 'P8_13'
+
+# Define LCD column and row size for 16x2 LCD.
+lcd_columns = 16
+lcd_rows = 2
+
+# Alternatively specify a 20x4 LCD.
+# lcd_columns = 20
+# lcd_rows = 4
+
+# Initialize the LCD using the pins
+lcd = LCD.Adafruit_RGBCharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
+ lcd_columns, lcd_rows, lcd_red, lcd_green, lcd_blue,
+ enable_pwm=True)
+
+# Show some basic colors.
+lcd.set_color(1.0, 0.0, 0.0)
+lcd.clear()
+lcd.message('RED')
+time.sleep(3.0)
+
+lcd.set_color(0.0, 1.0, 0.0)
+lcd.clear()
+lcd.message('GREEN')
+time.sleep(3.0)
+
+lcd.set_color(0.0, 0.0, 1.0)
+lcd.clear()
+lcd.message('BLUE')
+time.sleep(3.0)
+
+lcd.set_color(1.0, 1.0, 0.0)
+lcd.clear()
+lcd.message('YELLOW')
+time.sleep(3.0)
+
+lcd.set_color(0.0, 1.0, 1.0)
+lcd.clear()
+lcd.message('CYAN')
+time.sleep(3.0)
+
+lcd.set_color(1.0, 0.0, 1.0)
+lcd.clear()
+lcd.message('MAGENTA')
+time.sleep(3.0)
+
+lcd.set_color(1.0, 1.0, 1.0)
+lcd.clear()
+lcd.message('WHITE')
+time.sleep(3.0)
+
+# Use HSV color space so the hue can be adjusted to see a nice gradient of colors.
+# Hue ranges from 0.0 to 359.0, saturation from 0.0 to 1.0, and value from 0.0 to 1.0.
+hue = 0.0
+saturation = 1.0
+value = 1.0
+
+# Loop through all RGB colors.
+lcd.clear()
+print('Press Ctrl-C to quit.')
+while True:
+ # Convert HSV to RGB colors.
+ red, green, blue = hsv_to_rgb((hue, saturation, value))
+ # Set backlight color.
+ lcd.set_color(red, green, blue)
+ # Print message with RGB values to display.
+ lcd.set_cursor(0, 0)
+ lcd.message('RED GREEN BLUE\n{0:0.2f} {1:0.2f} {2:0.2f}'.format(red, green, blue))
+ # Increment hue (wrapping around at 360 degrees).
+ hue += 1.0
+ if hue > 359.0:
+ hue = 0.0