generated from jbleakl36/CPyProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCD.py
More file actions
49 lines (44 loc) · 1.32 KB
/
LCD.py
File metadata and controls
49 lines (44 loc) · 1.32 KB
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
#Elias Garcia
#When a button is presses it increses or decreases the count based on the position of a switch
#Code from Grant Gastinger
import board
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
import time
from digitalio import DigitalInOut, Direction, Pull
# get and i2c object
i2c = board.I2C()
btn = DigitalInOut(board.D2)
btn.direction = Direction.INPUT
btn.pull = Pull.UP
clickCount = 0
btn2 = DigitalInOut(board.D3)
btn2.direction = Direction.INPUT
btn2.pull = Pull.UP
# some LCDs are 0x3f... some are 0x27...
lcd = LCD(I2CPCF8574Interface(i2c, 0x3f), num_rows=2, num_cols=16)
lcd.print("elias")
print("son, i am disapoint.")
while True:
if not btn2.value:
if not btn.value:
lcd.clear()
lcd.set_cursor_pos(0, 0)
lcd.print("Click Count:")
lcd.set_cursor_pos(0,13)
clickCount = clickCount + 1
lcd.print(str(clickCount))
else:
pass
else:
if not btn.value:
lcd.clear()
lcd.set_cursor_pos(0, 0)
lcd.print("Click Count:")
lcd.set_cursor_pos(0,13)
clickCount = clickCount - 1
lcd.print(str(clickCount))
else:
pass
print("btn1",btn.value," btn2",btn2.value)
time.sleep(0.1) # sleep for debounce