Putting robotics at your service™

Free shipping on orders over $75

controlling more than one servo

Print view Share :
Previous topicNext topic

Page 1 of 1 [ 1 post ]

New ( offline )
Posts: 3
Posted: 2011-12-12 12:12 
Hello all,
sorry about this newb question but this is my first time i am building a robot and i dont know who to code the ps2_dualshock program to run mor than one servo. any help on this would be great.
i am using a basic atom pro 28 with a bot board 2 with IDE V. 5

;[PS2 Controller Constants]
PS2_DAT             con P12      ;PS2 Controller DAT (Brown)
PS2_CMD             con P13      ;PS2 controller CMD (Orange)
PS2_ATT             con P14      ;PS2 Controller SEL (Blue)
PS2_CLK             con P15      ;PS2 Controller CLK (White)

PS2_MODE             con $79

;[Ps2 Controller Variables]
PS2_data             var Byte(18)
PS2_lastbutton         var Byte(2)
PS2_work            var Byte
PS2_Index            var byte

   gosub ControlInput[PS2_data(16),PS2_data(17)]
   serout s_out,i38400,[0," DPad-Left: ",bin1 PS2_data(0).bit7\1," ",dec PS2_data(7),13]
   serout s_out,i38400,[" DPad-Down: ",bin1 PS2_data(0).bit6\1," ",dec PS2_data(9),13]
   serout s_out,i38400,[" DPad-Right: ",bin1 PS2_data(0).bit5\1," ",dec PS2_data(6),13]
   serout s_out,i38400,[" DPad-Up: ",bin1 PS2_data(0).bit4\1," ",dec PS2_data(8),13]
   serout s_out,i38400,["Right XAxis: ",sdec 128-PS2_data(2),13]
   serout s_out,i38400,["Right YAxis: ",sdec 128-PS2_data(3),13]
   serout s_out,i38400,[" Left XAxis: ",sdec 128-PS2_data(4),13]
   serout s_out,i38400,[" Left YAxis: ",sdec 128-PS2_data(5),13]
   serout s_out,i38400,[" Start: ",bin1 PS2_data(0).bit3\1,13]
   serout s_out,i38400,[" RAxis(R3): ",bin1 PS2_data(0).bit2\1,13]
   serout s_out,i38400,[" LAxis(L3): ",bin1 PS2_data(0).bit1\1,13]
   serout s_out,i38400,[" Select: ",bin1 PS2_data(0).bit0\1,13]
   serout s_out,i38400,[" Square: ",bin1 PS2_data(1).bit7\1," ",dec PS2_data(13),13]
   serout s_out,i38400,[" Cross: ",bin1 PS2_data(1).bit6\1," ",dec PS2_data(12),13]
   serout s_out,i38400,[" Circle: ",bin1 PS2_data(1).bit5\1," ",dec PS2_data(11),13]
   serout s_out,i38400,[" Triangle: ",bin1 PS2_data(1).bit4\1," ",dec PS2_data(10),13]
   serout s_out,i38400,[" R1: ",bin1 PS2_data(1).bit3\1," ",dec PS2_data(15),13]
   serout s_out,i38400,[" L1: ",bin1 PS2_data(1).bit2\1," ",dec PS2_data(14),13]
   serout s_out,i38400,[" R2: ",bin1 PS2_data(1).bit1\1," ",dec PS2_data(17),13]
   serout s_out,i38400,[" L2: ",bin1 PS2_data(1).bit0\1," ",dec PS2_data(16),13]
   pause 100
   goto main
;usage:   gosub ControlInput[motorww,motoryy]
 motorww = motorww power level
 motoryy = motoryy power level
PS2_motorww var byte
PS2_motoryy var byte
ControlInput [PS2_motorww,PS2_motoryy]
   high PS2_CLK
   PS2_lastbutton(0) = PS2_data(1)
   PS2_lastbutton(1) = PS2_data(2)
   low PS2_ATT
   shiftout PS2_CMD,PS2_CLK,LSBPRE,[$1\8]
   shiftin PS2_DAT,PS2_CLK,LSBPOST,[PS2_work\8]
   high PS2_ATT
   pause 1
   if PS2_work <> PS2_MODE THEN
      low PS2_ATT
      shiftout PS2_CMD,PS2_CLK,LSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;enter config mode
      high PS2_ATT
      pause 1

      low PS2_ATT
      shiftout PS2_CMD,PS2_CLK,LSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;set and lock analog mode
      high PS2_ATT
      pause 1

      low PS2_ATT
      shiftout PS2_CMD,PS2_CLK,LSBPRE,[$01\8,$4D\8,$00\8,$00\8,$01\8,$FF\8,$FF\8,$FF\8,$FF\8] ;Enable Vibration motors
      high PS2_ATT
      pause 1

      low PS2_ATT
      shiftout PS2_CMD,PS2_CLK,LSBPRE,[$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;set 18byte reply
      high PS2_ATT
      pause 1

      low PS2_ATT
      shiftout PS2_CMD,PS2_CLK,LSBPRE,[$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;exit config mode
      high PS2_ATT
      pause 1

      PS2_data(1) = 255,255
      goto ControlInput_Retry
      low PS2_ATT
      shiftout PS2_CMD,PS2_CLK,LSBPRE,[$1\8,$42\8, $00\8]   
      shiftin PS2_DAT,PS2_CLK,LSBPOST,[PS2_data(0)\8, PS2_data(1)\8]
      high PS2_ATT
      low PS2_ATT
      shiftout PS2_CMD,PS2_CLK,LSBPRE,[$1\8,$42\8, $00\8,PS2_motorww\8,PS2_motoryy\8]
      shiftin PS2_DAT,PS2_CLK,LSBPOST,[PS2_data(2)\8, PS2_data(3)\8, PS2_data(4)\8, PS2_data(5)\8, |
                                 PS2_data(6)\8, PS2_data(7)\8, PS2_data(8)\8, PS2_data(9)\8, |
                                 PS2_data(10)\8, PS2_data(11)\8, PS2_data(12)\8, PS2_data(13)\8, |
                                 PS2_data(14)\8, PS2_data(15)\8, PS2_data(16)\8, PS2_data(17)\8]
      high PS2_ATT


All times are UTC - 5 hours [ DST ]. It is currently 2015-09-04 08:19
Feedback Form