MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / lcdPrint

Function lcdPrint

lcdprint.py:13–86  ·  view source on GitHub ↗
(passedIn)

Source from the content-addressed store, hash-verified

11 import lcd2004
12
13def lcdPrint(passedIn):
14
15 # The PCF8574 has a jumper selectable address: 0x20 - 0x27
16 DEFAULT_I2C_ADDR = 0x27
17 foundLCD = False
18
19 mess = passedIn
20 if mess == "":
21 mess = input("Say what?: ")
22
23 i2c = None
24 for i2cNo in range(3):
25 try:
26 i2c = Pydos_hw.I2C(i2cNo)
27 except:
28 pass
29 if i2c:
30 if sys.implementation.name.upper() == "CIRCUITPYTHON":
31 # circuitpython seems to require locking the i2c bus
32 while not i2c.try_lock():
33 pass
34
35 if DEFAULT_I2C_ADDR in i2c.scan():
36 foundLCD = True
37 break
38
39 if sys.implementation.name.upper() == 'CIRCUITPYTHON':
40 i2c.unlock()
41
42 if not foundLCD:
43 print("LCD not found at address: ",hex(DEFAULT_I2C_ADDR))
44 return
45
46 if sys.implementation.name.upper() == "CIRCUITPYTHON":
47
48 # 2 lines, 16 characters per line
49 lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)
50
51 # smiley faces as custom characters
52 happy = bytearray([0x00,0x0A,0x00,0x04,0x00,0x11,0x0E,0x00])
53 heart = bytearray([0x00,0x00,0x0A,0X15,0X11,0X0A,0X04,0X00])
54 grin = bytearray([0x00,0x00,0x0A,0x00,0x1F,0x11,0x0E,0x00])
55 lcd.custom_char(0, happy)
56 lcd.custom_char(1, heart)
57 lcd.custom_char(2, grin)
58
59 else:
60 lcd=lcd2004.lcd(DEFAULT_I2C_ADDR,i2c)
61 lcd.lcd_backlight(True)
62 lcd.lcd_clear()
63
64 if mess == "":
65 if sys.implementation.name.upper() == "CIRCUITPYTHON":
66 lcd.backlight_off()
67 else:
68 lcd.lcd_backlight(False)
69 else:
70

Callers 1

lcdprint.pyFile · 0.85

Calls 10

inputFunction · 0.90
I2cLcdClass · 0.90
I2CMethod · 0.80
custom_charMethod · 0.80
lcd_backlightMethod · 0.80
lcd_clearMethod · 0.80
backlight_offMethod · 0.80
move_toMethod · 0.80
putstrMethod · 0.80
lcd_printMethod · 0.80

Tested by

no test coverage detected