Skip to content

Commit

Permalink
Merge pull request #57 from Capstone-Projects-2024-Spring/GPIOZeroBlo…
Browse files Browse the repository at this point in the history
…ckTask

GpioZero blocky started code
  • Loading branch information
gummyfrog committed Mar 20, 2024
2 parents 411de77 + 84019dc commit 0284b02
Showing 1 changed file with 37 additions and 0 deletions.
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")

0 comments on commit 0284b02

Please sign in to comment.