feat(swan_r5): user button tested
This commit is contained in:
parent
40c3b5c7e6
commit
599368373e
21
ports/stm/boards/swan_r5/tests/button.py
Normal file
21
ports/stm/boards/swan_r5/tests/button.py
Normal 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)
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user