Skip to content

Instantly share code, notes, and snippets.

@meub

meub/pi-servo.py

Last active Dec 25, 2020
Embed
What would you like to do?
Raspberry Pi Bell Ringer
#!/usr/bin/env python
import time
import RPi.GPIO as GPIO # Importing the GPIO library
from time import sleep # Import sleep module from time library
# Set up GPIO
servo_pin = 21 # GPIO Pin where servo is connected
GPIO.setmode(GPIO.BCM)
# Define the Pin numbering type and define Servo Pin as output pin
GPIO.setup(servo_pin, GPIO.OUT)
p = GPIO.PWM(servo_pin, 50) # PWM channel at 50 Hz frequency
p.start(0) # Zero duty cycle initially
# Hammer time!
sleep(0.4)
p.ChangeDutyCycle(6)
sleep(0.4)
p.ChangeDutyCycle(12)
sleep(0.25)
p.ChangeDutyCycle(6)
sleep(0.4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment