-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCD_Assignment_Button_Press_8-26.py
More file actions
64 lines (50 loc) · 1.7 KB
/
LCD_Assignment_Button_Press_8-26.py
File metadata and controls
64 lines (50 loc) · 1.7 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#Graham Lenert
#LCD Assignment Button Press
#This assignment; when you press a button, the counter goes up or down
#on the LCD screen depending on which way a switch is flipped
#LCD Screen
import board
#import neopixel
import math
import time
import digitalio
import adafruit_bus_device
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface #importing and prepping LCD library
from lcd.lcd import CursorMode
lcd = LCD(I2CPCF8574Interface(0x3f), num_rows=2, num_cols=16)
#^ defines the dimensions of the LCD screen
#sets pin 7 to an input
inputPin = digitalio.DigitalInOut(board.D7)
inputPin.direction = digitalio.Direction.INPUT
inputPin.pull = digitalio.Pull.UP
#Sets the pin 8 to an Input
button = digitalio.DigitalInOut(board.D8)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP
counter = 0 #sets counter to 0
oldSwitchState = 0 #States the Old State to 0 (Switch starts off)
newSwitchState = 1 #States the New State to 1(Updating switch starts on)
adder = 1
while True:
lcd.clear()
lcd.set_cursor_pos(0,0) #clears and resets LCD
lcd.print("Presses: ") # Sets the amount of Button Presses
lcd.set_cursor_pos(1,0)
lcd.print(str(counter))
if button.value:
print("0")
time.sleep(0.05)
oldSwitchState = 0
elif oldSwitchState == 0 and newSwitchState == 1:
if inputPin.value:
adder = 1
else:
adder = -1
#Only Prints when Button is Pressed then Released
print("1")
#print(str(adder))
time.sleep(0.05)
counter += adder
oldSwitchState = 1
#Resets The Variables (Sets the Button to Unpressed)