Fellow Sparkers,
After trying and adjusting I finally managed to move 1 pan-tilt bracket, using a Joystick widget.
In my Python code I included 1 Vpin. The Joystick widget uses the merge function, so I use V1 tot write my code and merge the x and y axis.
Today I wanted to use 3 brackets at the same time. I got 3 joystick widgets within the same project. And started to create a V1, V2 and V3 pin code in my existing script. The experienced Blynkers already see it coming: that did not work out… I tested all kinds of ways, without the desired outcome. I did learn and see al kinds of combinations that result in all three brackets moving the same way for example. However, it is always nice to see “a” result!
Can somebody steer me into the right direction? I have 3 brackets. I want 1 project with 3 joystick widgets. Every widget should solely move 1 bracket.
Should I continue working on the python code,or do I have to look at multile devices? It does seem strange to get 3 auth tokens for 3 different brackets.
My biggest hurdle is the main code for the Joystick widget. I have devided my x en y axis into JoystickX en JoystickY. This results in me placing this basic code under every Vpin (1,2,3). But because there is no further distinction between JoystickX and JoystickY these terms are the same for every Vpin I use. At the end it seems that only the last code written under V3 is being processed, so only bracket 3 moves. I even saw 3 widgets move solely bracket 3.
As you can read I am pretty stuck and not very experencied. Can somebody help me out?
Using: Raspberry Pi zero, Pi servo pHAT (v2).
Code:
import busio
import adafruit_pca9685
i2c = busio.I2C(board.SCL, board.SDA)
hat = adafruit_pca9685.PCA9685(i2c)
hat.frequency = 50
import time
from adafruit_servokit import ServoKit
kit = ServoKit(channels=16)
angleX = 0
angleY = 1
kit.servo[0].angleX = 0
kit.servo[1].angleY = 0
import blynklib
from BlynkTimer import BlynkTimer
timer = BlynkTimer()
def limit(value, lower, upper):
if value < lower:
value = lower
elif value > upper:
value = upper
return value
auth_token = 'XXX'
# Initialize Blynk
blynk = blynklib.Blynk(auth_token)
@blynk.handle_event('write V1') # Joystick
def V1_write_handler_pin_handler(pin, value):
global joystick_mode, angleX, angleY
joystickX = int(value[0])
joystickY = int(value[1])
# PanTilt
if joystickX > 30: angleX = 4
elif joystickX < -30: angleX = -4
else: angleX = 0
if joystickY > 30: angleY = 4
elif joystickY < -30: angleY = -4
else: angleY = 0
print("angle {} {} ".format(angleX,angleY))
def panTiltMove():
global angleX, angleY
kit.servo[0].angle = limit(kit.servo[0].angle - angleX, 0, 180)
kit.servo[1].angle = limit(kit.servo[1].angle - angleY, 0, 180)
timer.set_interval(0.1, panTiltMove) # 100ms
try:
while True:
blynk.run()
timer.run()
except KeyboardInterrupt:
print("Quit")```