3D Printed Raspberry Pi Pan Tilt Camera with Game Pad Control
Admit it, if you have been following my recent articles, you knew this was coming ;)
Let's pull these things together!
We know these servos accept a maximum and minimum pulse width (signal), so all we do is increment and decrement while checking for those values.
I was asked why I am using the buttons instead of the joysticks. The answer is, it's simply easier to show the code right now if we keep it simple. Keep following these articles and all will become clear ;)
from evdev import InputDevice
import pigpio
pi = pigpio.pi()
tilt = 17
pan = 27
x = 1250
y = 1250
# want to display ALL info?
debug = False
if debug:
for device in evdev.list_devices():
print(evdev.InputDevice(device))
input("Press Enter to continue ...")
# create object to read input - specify YOUR device
controller = InputDevice('/dev/input/event0')
# what are the controller details?
if debug:
print(controller)
# read controller info in an infinite loop
for event in controller.read_loop():
# here I am looking for the start button
# so I can quit
if event.type == 1:
exit()
# set as true above if you want to look up
# different button values
if debug:
print("\n\nEvent Type:{}".format(event.type))
print("Event Code:{}".format(event.code))
print("Event Value:{}".format(event.value))
# look for pad moves
if event.type == 3:
# up and down is 17
if event.code == 17:
if event.value == 1:
print("\n\n\nPad Up\n")
if y > 600: y -= 100
if event.value == -1:
print("\n\n\nPad Down\n")
if y < 2400:y += 100
pi.set_servo_pulsewidth(tilt, y)
# left and right is 16
if event.code == 16:
if event.value == -1:
print("\n\n\nPad Left\n")
if x > 600: x -= 100
if event.value == 1:
print("\n\n\nPad Right\n")
if x < 2400: x += 100
pi.set_servo_pulsewidth(pan, x)
Join our Discord Channel to connect with us and nominate your own or somebody else's posts in our review channel.
Help us to reward you for making it ! Join our voting trail or delegate steem power to the community account.
Your post is also presented on the community website www.steemmakers.com where you can find other selected content.
If you like our work, please consider upvoting this comment to support the growth of our community. Thank you.
I will keep following along, guess this is a part of a bigger project, Robot?
Yep!