from machine import Pin
from time_base import Time_base
from gpio_led import Led
from signal_generator import Signal, SAMPLE
from dac import DAC
from gpio_button import Button
from keypad_polling import KeyPad
cont = 0
my_led = Led(18, False)
tb_print = Time_base(500000, True)
my_signal = Signal(100, 1000, 500, True)
my_signal.calculate()
my_dac = DAC(10, True)
my_button = Button(0, 100000, True)
my_keypad = KeyPad(2, 6, 100000, True)
while True:
if tb_print.check():
tb_print.set_next()
# print("Contador: ", cont)
cont += 1
my_led.toggle()
my_dac.set_dac(2000)
# print("dkey: 0x{0:02x}".format(my_keypad.dkey))
# Get the keypad columns
my_keypad.captureCols()
# Process the keypad
if ((my_keypad.cols != 0x0f) & (not my_keypad.dbnc)):
my_keypad.tb_seq.disable()
my_keypad.captureKey() # Capture the key
my_keypad.tb_dbnce.update()
my_keypad.tb_dbnce.enable()
my_keypad.set_zflag()
my_keypad.dbnc = True
print("Key pressed")
if (my_keypad.tb_seq.check()):
my_keypad.tb_seq.set_next()
my_keypad.gen_seq()
if (my_keypad.tb_dbnce.check()):
my_keypad.tb_dbnce.set_next()
if (my_keypad.is_2nd_zero()):
if (my_keypad.cols == 0x0f):
my_keypad.tb_seq.update()
my_keypad.tb_seq.enable()
my_keypad.tb_dbnce.disable()
my_keypad.dbnc = False
print("dkey: 0x{0:02x}".format(my_keypad.dkey))
else:
my_keypad.clear_zflag()
else:
if (my_keypad.cols == 0x0f):
my_keypad.set_zflag()
# Process the button
boolButton: bool = bool(my_button.gpioPin.value())
if ((not boolButton) & (not my_button.dbnc)):
my_button.nkey = True # A key was pressed
my_button.tb_dbnce.update()
my_button.tb_dbnce.enable()
my_button.dbnc = True
if (my_button.tb_dbnce.check()):
my_button.tb_dbnce.set_next()
if (my_button.is_2nd_zero()):
if (boolButton):
my_signal.set_ss((my_signal.ss + 1) % 4)
my_signal.calculate()
my_button.tb_dbnce.disable()
my_button.dbnc = False
print("The button was proccessed")
else:
my_button.clear_zflag()
else:
if (boolButton):
my_button.set_zflag()