-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd_functions.py
executable file
·59 lines (42 loc) · 1.29 KB
/
lcd_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python
import time
import Adafruit_CharLCD as LCD
# Raspberry Pi configuration:
lcd_rs = 27
lcd_en = 22
lcd_d4 = 25
lcd_d5 = 24
lcd_d6 = 23
lcd_d7 = 18
lcd_red = 5
lcd_green = 17
lcd_blue = 7
# Define LCD column and row size for 16x2 LCD.
lcd_columns = 16
lcd_rows = 2
## 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, enable_pwm=True)
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
lcd_columns, lcd_rows, backlight=16, enable_pwm=True)
# Basic colors
colors = {'red': (1.0, 0.0, 0.0),
'green': (0.0, 1.0, 0.0),
'blue': (0.0, 0.0, 1.0),
'yellow': (1.0, 1.0, 0.0),
'cyan': (0.0, 1.0, 1.0),
'magenta': (1.0, 0.0, 1.0),
'white': (1.0, 1.0, 1.0)}
def get_colors(color):
"""returns tuple of numeric color representation"""
c = colors[color]
return c[0], c[1], c[2]
def display_text(text, color='cyan'):
"""prints text to LCD"""
# get color values
c0, c1, c2 = get_colors(color)
# display text
lcd.clear()
#lcd.set_color(c0, c1, c2)
lcd.message(text)