feat(swan_r5): user button tested

This commit is contained in:
Matthew McGowan 2021-09-28 09:14:38 -07:00
parent 40c3b5c7e6
commit 599368373e
2 changed files with 21 additions and 1 deletions

View File

@ -0,0 +1,21 @@
import board
import digitalio
import time
def monitor_button(pin, callback):
with digitalio.DigitalInOut(pin) as button:
newstate = not button.value # state is inverted
state = not newstate # ensure change reported to start with
while callback(newstate, newstate!=state):
state = newstate
newstate = button.value
time.sleep(0.01)
def print_changes(state, changed):
if changed:
print(f"button pressed {state}")
return True
monitor_button(board.BUTTON_USR, print_changes)

View File

@ -38,7 +38,6 @@ void stm32_peripherals_gpio_init(void) {
__HAL_RCC_GPIOG_CLK_ENABLE();
// Never reset pins
never_reset_pin_number(2,13); // PC13 anti tamp
never_reset_pin_number(2,14); // PC14 OSC32_IN
never_reset_pin_number(2,15); // PC15 OSC32_OUT
never_reset_pin_number(0,13); // PA13 SWDIO