Untitled
unknown
plain_text
3 years ago
725 B
6
Indexable
import RPi.GPIO as GPIO
import time
# Set up GPIO pins
GPIO.setmode(GPIO.BCM)
led_pin = 17 # GPIO pin for the LED (BCM numbering)
GPIO.setup(led_pin, GPIO.OUT)
# Function to control the LED
def control_led(state):
GPIO.output(led_pin, state)
# Main program loop
while True:
user_input = input("Enter '1' to turn the LED on, '0' to turn it off, or 'q' to quit: ")
if user_input == '1':
control_led(GPIO.HIGH) # Turn the LED on
elif user_input == '0':
control_led(GPIO.LOW) # Turn the LED off
elif user_input.lower() == 'q':
break # Exit the program
else:
print("Invalid input. Try again.")
# Clean up GPIO on exit
GPIO.cleanup()
Editor is loading...