I cant get mo robot working!
Mbiddle
Posts: 2
I have a problem with my servos, they will not work with the buttons on my Ps2 controller. Ive tried just about everything. Does anyone know whats wrong with this section of code.
if |< 26
servo[6] := (!buttons & |< 26 - 128) * vspeed
if |< 27
servo[3] := (!buttons & |< 27 - 128) * vspeed
if |< 24
servo[6] := (128 - !buttons & |< 24) * vspeed
if |< 25
servo[3] := (128 - !buttons & |< 25) * vspeed
repeat vspeed := 4
if !buttons & |< 26 'L1
pst.Str (String (" L1_ON: "))
dira [22] := 1
outa [22] := 1
elseifnot buttons == 1
outa [22] := 0
if !buttons & |< 24 'L2
pst.Str(String(" L2_ON: "))
dira [22] := 1
outa [22] := 1
elseifnot buttons == 1
outa [22] := 0
if !buttons & |< 27 'R1
pst.Str(String(" R1_ON: "))
dira [21] := 1
outa [21] := 1
elseifnot buttons == 1
outa [21] := 0
if !buttons & |< 25 'R2
pst.Str (String (" R2_ON: "))
dira [21] := 1
outa [21] := 1
if |< 26
servo[6] := (!buttons & |< 26 - 128) * vspeed
if |< 27
servo[3] := (!buttons & |< 27 - 128) * vspeed
if |< 24
servo[6] := (128 - !buttons & |< 24) * vspeed
if |< 25
servo[3] := (128 - !buttons & |< 25) * vspeed
repeat vspeed := 4
if !buttons & |< 26 'L1
pst.Str (String (" L1_ON: "))
dira [22] := 1
outa [22] := 1
elseifnot buttons == 1
outa [22] := 0
if !buttons & |< 24 'L2
pst.Str(String(" L2_ON: "))
dira [22] := 1
outa [22] := 1
elseifnot buttons == 1
outa [22] := 0
if !buttons & |< 27 'R1
pst.Str(String(" R1_ON: "))
dira [21] := 1
outa [21] := 1
elseifnot buttons == 1
outa [21] := 0
if !buttons & |< 25 'R2
pst.Str (String (" R2_ON: "))
dira [21] := 1
outa [21] := 1
Comments
Welcome to the forum.
You are going to have to edit your post and add code markup around your code so that we can read it properly.
Look for the # button in the advanced edit box.
With out it the code has no indentation and the logical flow is lost.
Oh yes, and you may need to add a space after each opening square bracket [ and before each closing square bracket ] so that they don't get interpreted as text formatting by the forum.
This statement is always true.
Each button is an element of an array. If the element is one then the button is pressed.
So to check if the "R1" button is pressed you use:
The constant "_R1Ps2" is defined as four in the constant section.
The code can also read the analog values of the button pressure.
I made a demo of the object and posted it here.
Once the object is started all the button values and joystick values are continuously updated so the variable "rightX" always contains the most recent x value of the right joystick.
I also added the ability to change from digital to analog mode with software so you don't need to remember to press the "analog" button in order to use the joysticks.
I personally think the analog buttons are cool. This is the first object I know of to read the analog values of the buttons. I didn't even know the buttons were pressure sensitive a few weeks ago.
I hope you try it out. I think it's pretty darn cool (if I do say so myself).
Edit: I just added my version of the PS2 controller to the OBEX.
plus i dont understand what ur saying
your last post is too short to understand what you are not understanding.
please ask concrete questions like "I don't understand what you mean by writing ....."
or "I don't know what a ... is"
Best thing is to use the archive-function of the propeller-tool to put ALL files that are needed to compile into one zip-file and attaching this file to a posting.
a general advice about code-developing is to divide the code into small pieces and to test each piece on its own.
This will make it much easier to narrow down a problem.
best regards
Stefan