import time
from machine import Pin
time.sleep(0.1) # Wait for USB to become ready
#SETTING UP DISPLAYS
#arrays listing pin numbers for both displays corresponding A,B,C,D,E,F,G
#sections respectively
display1_list = [0,1,2,3,4,5,6]
display2_list = [16,17,18,19,20,21,22]
#arrays denoting each number. For example when all leds
#are lit except for G, number "0" will be displayed
num_arr = [[1,1,1,1,1,0,1], # -> displays 0
[0,1,1,0,0,0,0], # -> displays 1
[1,1,0,1,1,1,0], # -> displays 2
[1,1,1,1,0,1,0], # -> displays 3
[0,1,1,0,0,1,1], # -> displays 4
[1,0,1,1,0,1,1], # -> displays 5
[1,0,1,1,1,1,1], # -> displays 6
[1,1,1,0,0,0,0], # -> displays 7
[1,1,1,1,1,1,1], # -> displays 8
[1,1,1,1,0,1,1]] # -> displays 9
#in the above configuration, say num_arr[8] corresponds to the
#respective array for number "8"
#define empty array variables for each display to fill with necessary
#pin numbers,setting them as "out", by using a for loop
display1_obj = []
display2_obj = []
for pin in display1_list:
display1_obj.append(Pin(pin, Pin.OUT))
for pin in display2_list:
display2_obj.append(Pin(pin, Pin.OUT))
display1_obj[1].value(1)
#write a function that will light the relevant display sections
#by converting to a string, seperate first and last digits,
#then convert them back to numbers
def displayCounter(toDisplay):
temp = str(toDisplay)
if toDisplay < 0 or toDisplay > 99:
first = 0
second = 0
elif len(temp) == 1:
first = 0
second = int(temp)
elif len(temp) == 2:
first = int(temp[0])
second = int(temp[1])
for i in range(7):
display1_obj[i].value(num_arr[first][i])
for i in range(7):
display2_obj[i].value(num_arr[second][i])
#SETTING UP BUTTONS
#including each button in the code
button_1 = Pin(14, Pin.IN, Pin.PULL_UP)
button_2 = Pin(15, Pin.IN, Pin.PULL_UP)
#setting up a counter to keep track of the number that will be displayed
counter = 0
button_1_current_val = 1
button_2_current_val = 1
while True:
if button_1_current_val == 1:
if button_1.value() == 0:
counter += 1
button_1_current_val = 0
if button_2_current_val == 1:
if button_2.value() == 0:
counter -= 1
button_2_current_val = 0
button_1_current_val = button_1.value()
button_2_current_val = button_2.value()
displayCounter(counter)
print(counter)
time.sleep(0.01)