from machine import Pin
from time import sleep_ms
import _thread
import sys

Ctrl = [Pin(25, Pin.OUT), Pin(14, Pin.OUT), Pin(12, Pin.OUT), Pin(33, Pin.OUT)]
Nexie = [Pin(26, Pin.OUT), Pin(13, Pin.OUT), Pin(2, Pin.OUT), Pin(5, Pin.OUT), Pin(18, Pin.OUT), Pin(27, Pin.OUT), Pin(15, Pin.OUT), Pin(4, Pin.OUT)]
num_dict = ["00000011","10011111","00100101","00001101","10011001","01001001","01000001","00011011","00000001","00001001"]

def Nexie_init():
    for x in Ctrl:
        x.value(0)
    for x in Nexie:
        x.value(1)

num='888'

def get_num(*args, **kwargs):
    global num
    while True:
#         num = random.randint(1, 999)
#         if Pin(19,Pin.IN).value()==1:
#             sleep_ms(5000)
        for x in range(10000):
            num = x
            sleep_ms(100)

def show_num(*args, **kwargs):
    while True:
        global num
        s = str(num)
        for n in range(len(s)):
            
            Nexie_init()
            Ctrl[n-len(s)].value(1)

            for x in range(8):
                Nexie[x].value(int(num_dict[int(s[n])][x]))
                
            sleep_ms(6)
            
thread_1 = _thread.start_new_thread(get_num, (1,))
thread_2 = _thread.start_new_thread(show_num, (2,))