From 3f2a0db9a3dcc0f8db696d189a38e5e5344d6d99 Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Mon, 11 Nov 2019 09:10:34 +0000 Subject: [PATCH] add sample to turn LED on and off via button --- 2_BUTTON/button_function.py | 7 +++---- 2_BUTTON/button_turnOnLED.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 2_BUTTON/button_turnOnLED.py diff --git a/2_BUTTON/button_function.py b/2_BUTTON/button_function.py index 00760bc..0aa0424 100644 --- a/2_BUTTON/button_function.py +++ b/2_BUTTON/button_function.py @@ -1,11 +1,10 @@ from gpiozero import Button +from gpiozero import LED from signal import pause -def say_hello(): - print("Hello!") - +led_green = LED(18) button = Button(23) -button.when_pressed = say_hello + led_green.toggle() pause() diff --git a/2_BUTTON/button_turnOnLED.py b/2_BUTTON/button_turnOnLED.py new file mode 100644 index 0000000..c300e0a --- /dev/null +++ b/2_BUTTON/button_turnOnLED.py @@ -0,0 +1,11 @@ +from gpiozero import Button +from signal import pause + +def say_hello(): + print("Hello!") + +button = Button(23) + +button.when_pressed = say_hello + +pause()