Curses and PanTiltHat

I’m trying to use the Pan Tilt Hat with my Raspberry Pi using the module curses. Im having a tough time figuring out the code to make the Hat move with the arrow keys. I’m running a While True loop.

For example:

X=0

If char == curses.KEY_UP:
pantilthat.servo_two(x)
x+=1

For each instance I want the Servo to move up. My problem is that the x value will always reset to 0 after the instance is completed. Is there a way to fix this?

1 Like

I figured it out. Wasn’t easy.

I am happy I found your posting regarding how to control PanTiltHat. My idea is to move my PanTiltHat using the arrow keys. As long as I keep the arrow pressed, the corresponding servo moves. Is that what I can do ? Have I got the right idea ?
As “Module curses” is totally unknown to me, could you please tell how you solved the problem. A short shell python listing would be highly appreciated ?

Thanx in advance

calleblyh

If you post your code between three ` and then three more, it will show correctly indent wise etc

your code here

It’s the key with the ~ on it right below the Esc key. Assuming you don’t mind sharing your code. ;)

https://docs.python.org/3/howto/curses.html

Use this link to get curses set and use pan tilt hat library instead of the print statements. What I did was make a class and within that class I made functions for move left, move right, move up, move down. It’s possible to use the global function to make a variable increment after and replace the current value. It’s just not good practice because it makes the code hard to read.

I did some searching on CURSES and found something which could fit my application perfect. “https://github.com/tuckershannon/PanTilt/commit/24fffc9f8232147642243babc067af83ba80cfde”. However try to run the pantilt.py I get an error: cannot create /dev/servoblaster: Permission denied. apparently because servod is not installed. So how do I overcome this problem ?
Asking for hepoing advice .
Thanx in Advance