Untitled
unknown
plain_text
2 years ago
722 B
7
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 = int ( input("Enter '1' to turn the LED on, '0' to turn it off, or '-1' 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 == -1: break # Exit the program else: print("Invalid input. Try again.") # Clean up GPIO on exit GPIO.cleanup()
Editor is loading...