United Kingdom
Asked — Edited
Resolved Resolved by Dunning-Kruger!

Scripting Joystick Buttons

Hello there.

I need a little help with something, but I'm not sure if it is even possible. Is there a way to use one joystick button to move a servo in to two positions with two presses. Here's what I mean...

Servo is at center (possition 90)

Press button 1 and servo turns left (possition 1).

No button release script so servo stays left (possition 1).

Press button 1 again, and servo moves back to center (possition 90).

No button release script, so servo stays center (possition 90).

Press button 1 and servo turns left (possition 1)

and so on.

I have had a look through the script menu but have not seen anything to help me accomplish this (unless I missed it of course) and I'm not sure if it is even possible. I would like to do this just so I can free up some buttons on my controller.

If anyone has had experience with this or know what script to use, then your help would be most appreciated. :)

Steve.


ARC Pro

Upgrade to ARC Pro

Subscribe to ARC Pro, and your robot will become a canvas for your imagination, limited only by your creativity.

#1  

Of course... behind the button is scripts that will run when the button is pressed or released... You will have to set $button1=1 somewhere else in an init type of script prior to using the button the first time...

in the script of whatever button you want to use to run the servo..


if $button1=1
servo(D0,1) #when button is pressed servo will move to position 1
$button1=0
else
servo(D0,90) #when button is pressed again servo will move to position 90
$button1=1
endif

#2  

Here is where you enter the above script in the joystick control, (button tab)

User-inserted image

United Kingdom
#3  

@Richard.

Thanks for the script example. That was exactly what I was looking for and I had a feeling this would be possible. Still really new at scripting so I'm still finding my way around. I already knew where and how to add script as I have been using this already, but it's what script to use and what some of the scripts do is what I need to understand better. Some of the script examples in the menu for me are easy enough to understand and self explanitory, but some I am still trying to get my head around confused but I'll get there.

Will try your script a bit later and let you know how I got on.

United Kingdom
#4  

Ok, so i tried the script and ran in to a problem. What am i doing wrong?

if $button1=1
servo(D13,88)
$button1=0
else
servo(D13,62)
$button1=1
endif
#5  

Is the script mapped to the correct button? What is the script doing or not doing exactly?

#6  

@Steve G.... What do you mean by scripting buttons? So we're not talking about the joystick buttons at all then? Can you post a screen shot, maybe?

United Kingdom
#7  

Yeah, I am talking about joystick buttons. I click on to button 1 multi script and put the code in for when button 1 is pressed but no script for when button 1 is released, saved it then saved again. I go to try the script and the diagnostic list says "error in line 1". Battery is charging at the mo, so will do a screen shoot in a bit.

User-inserted image

User-inserted image

#8  

if you get an error in line one it might be because your program needs to set $button1 to equal 1 in another script before you use the joystick control...

Although you do not need to declare variables in ARC, you still need to set a preliminary value (sort of) before you use them for the first time...

I mentioned to use an init script and type or even in your servo speed script if you like $button1=1

then use the joystick control...