import machine
import utime
try: # starts executing the code once the start comand is given
# in this way I can use the except function for the end conditions
# 7 segment displayer Pin numbers
# Every singal one of these pins corresponds to a specific LED line on the displayer
display_pins = [16, 17, 18, 19, 13, 14, 15]
#[Middle(G),Top Left(F),Top(A),Top Right(B),Bottom Rigth(C),Bottom(D),Bottom Left(E)]
# List of LED combinations of numbers:
chars = [
[1, 0, 0, 0, 0, 0, 0], # 0
[1, 1, 1, 0, 0, 1, 1], # 1
[0, 1, 0, 0, 1, 0, 0], # 2 1 means turn off the LED corresponds to that Pin number.
[0, 1, 0, 0, 0, 0, 1], # 3 Since our displayers are anothe, 1 turns off and 0 turns on.
[0, 0, 1, 0, 0, 1, 1], # 4
[0, 0, 0, 1, 0, 0, 1], # 5
[0, 0, 0, 1, 0, 0, 0], # 6
[1, 1, 0, 0, 0, 1, 1], # 7
[0, 0, 0, 0, 0, 0, 0], # 8
[0, 0, 0, 0, 0, 0, 1] # 9
]
# Assigning Pin numbers to the circut components
display_pins = [machine.Pin(pin_num, machine.Pin.OUT) for pin_num in display_pins]
button_1 = machine.Pin(8, machine.Pin.IN) # Pin number of the first button
button_2 = machine.Pin(9, machine.Pin.IN) # Pin number of the second button
control_sevenPin_1 = machine.Pin(2, machine.Pin.OUT) # Pin number of first dilplayer that displays tens
control_sevenPin_2 = machine.Pin(3, machine.Pin.OUT) # Pin number of second dilplayer that displays ones
counter = 0
# j=2 18. pin (0-6), chars'da 18.pin'in değeri 2. index'te ya yanıyor ya sönüyor yani ya 0 ya 1 alıyor,
#bu sırasıyla hepsi 17,18 için yapılıyor hepsi buradan 1'er değer alıyor
def update_displays(counter):
utime.sleep(0.01) # To imitate the mechanic delay
while True:
a, b = divmod(counter, 10) # Counter = 10a+b
#print("You are inside")
control_sevenPin_1.value(1) # Sends data only to the first displayer
control_sevenPin_2.value(0)
for i in range(7):
display_pins[i].value(chars[a][i]) # shows tens digit on the fisrt displayer
utime.sleep(0.01) # FIXED
# İlk ekranın gecikmesi daha uzun olmalı ki daha parlak gözüksün,
# çünkü fonksiyon en son 2. ekrana veri gönderip orada kalacak şekilde çalışmaya daha yatkın
control_sevenPin_1.value(0) # Sends data only to the second displayer
control_sevenPin_2.value(1)
for i in range(7):
display_pins[i].value(chars[b][i]) # shows ones digit on the second displayer
utime.sleep(0.0055)
if button_1.value()==True or button_2.value()==True: # When one of the buttons are pressed
print("OUTSIDER FEDERAL") # it exits this while loop and gets
# the new counter value
utime.sleep(0.005) # to give some time to the displayers when a button is pressed rapidly
break
while True:
#print("You are outside!: ", counter)
update_displays(counter)
if button_1.value() and button_2.value(): # Resets when both of the buttons are pressed
while button_1.value() or button_2.value(): # This loop is being executed only when one of the buttons are pressed
print("RESETSSS")
for i in range(5): # releated to the time passed right after both buttons are up again
a, b = divmod(counter, 10)
print("You are inside")
control_sevenPin_1.value(1)
control_sevenPin_2.value(0)
for i in range(7):
display_pins[i].value(chars[a][i])
utime.sleep(0.01)
control_sevenPin_1.value(0)
control_sevenPin_2.value(1)
for i in range(7):
display_pins[i].value(chars[b][i])
utime.sleep(0.01) # resetleme baþladýktan sonra tamamlana kadarki arada etki ediyor- affects the duration of reseting
utime.sleep(0.02) # resetleme sonrası gecikme- Delay time after the reset
counter = 0
else:
if button_1.value(): # Adds 1 when the first button is pressed
utime.sleep(0.03) # Creates a delay so it doesn't read the input twice
if counter != 99: # Doesn't read a value above 99
counter = (counter + 1)
else:
counter = counter
if button_2.value():
utime.sleep(0.03)
if counter != 0: # Doesn't read a value below 0
counter = (counter - 1)
else:
counter = counter
utime.sleep(0.1) # Number updating time after a button is pressed
except KeyboardInterrupt: # starts working once the stop comand is given
# gives the feedback of stop command to the user
print("Last line of code after clicking stop button")
for j in range(7): # Writes 0 on both of the displayers and stops the process
control_sevenPin_1.value(1)
control_sevenPin_2.value(1)
display_pins[j].value(chars[0][j])