# Motioneyeos

**URL:** <https://forums.pimoroni.com/t/motioneyeos/18907>\
**Category:** Projects\
**Created:** [February 17, 2022, 7:12pm UTC](https://forums.pimoroni.com/t/motioneyeos/18907 "2022-02-17T19:12:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scnet](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@scnet](https://forums.pimoroni.com/u/scnet)\
**Post date:** [February 17, 2022, 7:12pm UTC](https://forums.pimoroni.com/t/motioneyeos/18907/1 "2022-02-17T19:12:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [February 17, 2022, 9:13pm UTC](https://forums.pimoroni.com/t/motioneyeos/18907/2 "2022-02-17T21:13:24Z")

</div>

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.

```auto
import time
import pantilthat

currentPos = pantilthat.get_servo_one()
newPos = currentPos +5
if newPos >= 90: newPos = 90
pantilthat.servo_one(newPos)
time.sleep(1)

```

```auto
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

```

---

<div class="post-metadata">

**Author:** ![scnet](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@scnet](https://forums.pimoroni.com/u/scnet)\
**Post date:** [February 18, 2022, 3:35am UTC](https://forums.pimoroni.com/t/motioneyeos/18907/3 "2022-02-18T03:35:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [February 18, 2022, 9:52am UTC](https://forums.pimoroni.com/t/motioneyeos/18907/4 "2022-02-18T09:52:59Z")

</div>

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)](https://github.com/pimoroni/pantilt-hat/tree/master/examples)
