Untitled
unknown
plain_text
a year ago
801 B
7
Indexable
import RPi.GPIO as GPIO
from gpiozero import Servo
from time import sleep
# Set up GPIO
LED_PIN = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)
# Set up Servo
SERVO_PIN = 17
servo = Servo(SERVO_PIN)
try:
# Turn on the LED
GPIO.output(LED_PIN, GPIO.HIGH)
print("LED is ON")
# Move servo to 90 degrees
print("Moving servo to 90 degrees")
servo.value = 1 # Change to 1 for max, 0 for min (use -1 for 180 degrees if needed)
sleep(1) # Wait for 1 second
# Move servo back to 0 degrees
print("Moving servo back to 0 degrees")
servo.value = 0
sleep(1) # Wait for 1 second
finally:
# Clean up GPIO settings
GPIO.output(LED_PIN, GPIO.LOW)
GPIO.cleanup()
print("LED is OFF and GPIO cleaned up")
Editor is loading...
Leave a Comment