Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from Capstone-Projects-2024-Spring/GPIOZeroBlo…
…ckTask GpioZero blocky started code
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |