From 386f438a3554bddd2a8fa60cc17cb23a3952a993 Mon Sep 17 00:00:00 2001 From: Taylor Brown Date: Mon, 21 Feb 2022 16:32:34 -0600 Subject: [PATCH] Fix Python sensors sample The previous code doesn't compile and is incomplete. This commit stays as close to the intended original source while correctly compiling/functioning. --- .../asciidoc/accessories/build-hat/py-sensors.adoc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/documentation/asciidoc/accessories/build-hat/py-sensors.adoc b/documentation/asciidoc/accessories/build-hat/py-sensors.adoc index 686521852..889a251ce 100644 --- a/documentation/asciidoc/accessories/build-hat/py-sensors.adoc +++ b/documentation/asciidoc/accessories/build-hat/py-sensors.adoc @@ -18,12 +18,16 @@ from buildhat import ForceSensor, ColorSensor button = ForceSensor('C') cs = ColorSensor('B') -def handle_pressed(): +def handle_pressed(force): cs.on() - print(c.get_color()) + print(cs.get_color()) -def handle_released(): +def handle_released(force): cs.off() + +button.when_pressed = handle_pressed +button.when_released = handle_released +pause() ---- Run it and hold a coloured object (LEGO® elements are ideal) in front of the colour sensor and press the Force sensor plunger. The sensor’s LED should switch on and the name of the closest colour should be displayed in the thonny REPL.