Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GpioZero blocky started code #57

Merged
merged 2 commits into from Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions examples/GPIOZeroBlock.py
@@ -0,0 +1,37 @@
from gpiozero import Button, LED


#GPIO button on button 1
button = Button(5)


#led on pin 2
led = LED(2)


#boolean statement to check if button 1 is pressed or not
def checkPressed():
if button.is_pressed:
print("Button on pin 1 was pressed")
else:
print("Button on pin 1 was not pressed")


#function that executes function when button 1 is pressed
#two examples
def actionWhenPressed():
if button.is_pressed:
functionToComplete() #example for print statement
ledFunctionToComplete() #example using led light

#simple example function to print out if function works
def functionToComplete():
print("Function executed")

#example function to complete with led
def ledFunctionToComplete():
led.toggle()
if led.is_lit:
print("led 2 turned on")
else:
print("led 2 turned off")