From 41ff6b0ac96bd51aea744e12e2f5c84e98b2ddc4 Mon Sep 17 00:00:00 2001 From: Grace Date: Thu, 21 Mar 2024 14:38:41 +0000 Subject: [PATCH] Add pin touches sample --- src/demo.html | 1 + src/examples/pin_touches.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/examples/pin_touches.py diff --git a/src/demo.html b/src/demo.html index 83dabe83..75036482 100644 --- a/src/demo.html +++ b/src/demo.html @@ -92,6 +92,7 @@

MicroPython-micro:bit simulator example embedding

+ diff --git a/src/examples/pin_touches.py b/src/examples/pin_touches.py new file mode 100644 index 00000000..a9c33cc2 --- /dev/null +++ b/src/examples/pin_touches.py @@ -0,0 +1,12 @@ +from microbit import * + +def report_pin_touches(pin, p_num): + if pin.was_touched(): + print('pin', p_num, 'was touched', pin.get_touches(), 'time(s)') + +while True: + if pin_logo.is_touched(): + report_pin_touches(pin0, "0") + report_pin_touches(pin1, "1") + report_pin_touches(pin2, "2") + break