Motioneyeos

Anyone have a python code to use Pimoroni pan tilt hat and MotioneyeOS action buttons the ability to pan or tilt while action button pressed instead of the need to continually move until button released or second press

I have action button code python code, it’s x degrees moment per button click. My install script for one of my pan tilt camera setups is posted below. The bit I think your interseted in is as follows.

import time
import pantilthat

currentPos = pantilthat.get_servo_one()
newPos = currentPos +5
if newPos >= 90: newPos = 90
pantilthat.servo_one(newPos)
time.sleep(1)
mkdir /data/etc/python-scripts/
cat <<EOF >>/data/etc/left_1
#!/bin/bash
/usr/bin/python /data/etc/python-scripts/left.py
EOF
cat <<EOF >>/data/etc/right_1
#!/bin/bash
/usr/bin/python /data/etc/python-scripts/right.py
EOF
cat <<EOF >>/data/etc/up_1
#!/bin/bash
/usr/bin/python /data/etc/python-scripts/up.py
EOF
cat <<EOF >>/data/etc/down_1
#!/bin/bash
/usr/bin/python /data/etc/python-scripts/down.py
EOF
cat <<EOF >>/data/etc/preset1_1
#!/bin/bash
/usr/bin/python /data/etc/python-scripts/preset1.py
EOF
cat <<EOF >>/data/etc/preset2_1
#!/bin/bash
/usr/bin/python /data/etc/python-scripts/preset2.py
EOF
cat <<EOF >>/data/etc/preset3_1
#!/bin/bash
/usr/bin/python /data/etc/python-scripts/preset3.py
EOF
cat <<EOF >>/data/etc/preset4_1
#!/bin/bash
/usr/bin/python /data/etc/python-scripts/preset4.py
EOF
chmod +x /data/etc/left_1 /data/etc/right_1 /data/etc/up_1 /data/etc/down_1 /data/etc/preset1_1 /data/etc/preset2_1 /data/etc/preset3_1 /data/etc/preset4_1
cat <<EOF >>/data/etc/python-scripts/left.py
#!/usr/bin/python

import time
import pantilthat

currentPos = pantilthat.get_servo_one()
newPos = currentPos +5
if newPos >= 90: newPos = 90
pantilthat.servo_one(newPos)
time.sleep(1)
EOF
cat <<EOF >>/data/etc/python-scripts/right.py
#!/usr/bin/python

import time
import pantilthat

currentPos = pantilthat.get_servo_one()
#print (currentPos)
newPos = currentPos -5
if newPos <= -90: newPos = -90
pantilthat.servo_one(newPos)
time.sleep (1)
EOF
cat <<EOF >>/data/etc/python-scripts/up.py
#!/usr/bin/python

import time
import pantilthat

currentPos = pantilthat.get_servo_two()
#print (currentPos)
newPos = currentPos -5
if newPos <= -90: newPos = -90
pantilthat.servo_two(newPos)
time.sleep (1)
EOF
cat <<EOF >>/data/etc/python-scripts/down.py
#!/usr/bin/python

import time
import pantilthat

currentPos = pantilthat.get_servo_two()
newPos = currentPos +5
if newPos >= 90: newPos = 90
pantilthat.servo_two(newPos)
time.sleep(1)
EOF
cat <<EOF >>/data/etc/python-scripts/preset1.py
#!/usr/bin/python

import time
import pantilthat
pantilthat.tilt(0)
time.sleep(0.5)
pantilthat.pan(20)
time.sleep(0.5)
pantilthat.tilt(-20)
time.sleep(1)
EOF
cat <<EOF >>/data/etc/python-scripts/preset2.py
#!/usr/bin/python

import time
import pantilthat

pantilthat.tilt(0)
time.sleep(0.5)
pantilthat.pan(6)
time.sleep(0.5)
pantilthat.tilt(-16)
time.sleep(1)
EOF
cat <<EOF >>/data/etc/python-scripts/preset3.py
#!/usr/bin/python

import time
import pantilthat

pantilthat.tilt(0)
time.sleep(0.5)
pantilthat.pan(-44)
time.sleep(0.5)
pantilthat.tilt(-20)
time.sleep(1)
EOF
cat <<EOF >>/data/etc/python-scripts/preset4.py
#!/usr/bin/python

import time
import pantilthat

pantilthat.tilt(0)
time.sleep(0.5)
pantilthat.pan(-60)
time.sleep(0.5)
pantilthat.tilt(-13)
time.sleep(1)
EOF
cat <<EOF >>/data/etc/userinit.sh
sh -c 'echo 0 > /sys/class/leds/led1/brightness'
sh -c 'echo 0 > /sys/class/leds/led0/brightness'
EOF

Yes I have that code and it works great! However, I wish to continuously pan or tilt a few degrees every second for as long as I hold down the mouse button on the appropriate action button. By the way I noticed the action button calls the action script on the mouse button release rather than the mouse button ‘down.’ So that injects another complication. So what I am looking for is mouse/down to start incremental movement until mouse/up.

Ok, on my first read that was what I thought you wanted. Read it again and then wasn’t so sure and second guessed myself.
You may be able to click one button to start it moving and then click another one to stop it?. Have a look at the the code in the smoth.py example.
pantilt-hat/examples at master · pimoroni/pantilt-hat (github.com)