From 9a902049212ceea29b7b0e440acd33e3c63c7beb Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 17 Dec 2019 20:01:03 +0200 Subject: [PATCH] Add timer tests script. --- .../examples/02-Board-Control/timer_tests.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 scripts/examples/02-Board-Control/timer_tests.py diff --git a/scripts/examples/02-Board-Control/timer_tests.py b/scripts/examples/02-Board-Control/timer_tests.py new file mode 100644 index 000000000..6e8daa714 --- /dev/null +++ b/scripts/examples/02-Board-Control/timer_tests.py @@ -0,0 +1,25 @@ +# Timer Test Example +# +# This example tests all the timers. + +import time +from pyb import Pin, Timer, LED + +blue_led = LED(3) + +# Note: functions that allocate memory are Not allowed in callbacks +def tick(timer): + blue_led.toggle() + +print("") +for i in range(1, 18): + try: + print("Testing TIM%d... "%(i), end="") + tim = Timer(i, freq=10) # create a timer object using timer 4 - trigger at 1Hz + tim.callback(tick) # set the callback to our tick function + time.sleep(1000) + tim.deinit() + except ValueError as e: + print(e) + continue + print("done!")