Quote Originally Posted by lerameur View Post
ok I am doing a remote control for my robot I wrote a code below, It seems long, Maybe you have a better idea. I am using two Potentiometer , the values of each will control the left and right motor of the robot:

'Remote control*****************

direction var word : speed var word

Loop:
If (left => 115) AND (left <= 135) AND (right => 115) AND (right <= 135) then
goto stop

If (left => 115) AND (left <= 135) AND (right <= 115) then 'left is stop, right is CCW
goto LeftstopRightCCW

If (left => 115) AND (left <= 135) AND (right => 135) then 'left is stop , right is CW
goto LeftstopRightCW

If (right => 115) AND (right <= 135) AND (right <= 115) then 'right is stop, left is CCW
goto RightstopLeftCCW

If (right => 115) AND (right <= 135) AND (right => 135) then 'right is stop , left is CW
goto RightstopLeftCW

If (left > 135) AND (right > 135) then 'Left Cw & right CW
goto LeftCWRightCW

If (left > 135) AND (right < 135) then 'Left CW & right CCW
goto LeftCWRightCCW

If (left < 135) AND (right > 135) then 'Left CCW & right CW
goto LeftCCWRightCW

If (left < 135) AND (right < 135) then 'Left CCW & right CCW
goto LeftCCWRightCCW

In brief:
'Stop '--------------------------------$69 = 01 10 10 01
'Leftwheel =stop : Rightwheel= CCW '--- $A6 = 10 10 01 10
'Leftwheel =stop : Rightwheel= CW '----- $96 = 10 01 01 10
'Leftwheel =CCW : Rightwheel= stop '---- $9a = 10 01 10 10
'Leftwheel =CW : Rightwheel= stop '----- $A5 = 10 10 01 01
'Leftwheel =CW : Rightwheel= CW '---- $66 = 01 10 01 10
'Leftwheel =CW : Rightwheel= CCW '---- $56 = 01 01 01 10
'Leftwheel =CCW : Rightwheel= CW '---- $5a = 01 01 10 10
'Leftwheel =CCW : Rightwheel= CCW '---- $65 = 01 10 01 01

You're right. There probably is a better/shorter way to do that.
I'll think about it for a bit and get back to ya.
I take it that the reason you've got 115 and 135 is for a bit of a 'deadband' so the thing doesn't jitter on you?

(see that?, the manchester encoding is handy isn't it?)

How about


'Remote control*****************

direction var word : speed var word
bits var byte
'bits = bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
' LCW (-LCW) LCCW -(LCCW) RCW (-RCW) RCCW (-RCCW)
'use odd bits as a direction flag, use the even bits inverted from the others as the same thing, but also as a bit of error detection

TX end...

Loop:
bits = %01010101

If (left => 115) AND (left <= 135) then bits.7 = 0 : bits.6 = 1
if (right => 115) AND (right <= 135) then bits.3 = 0 : bits.2 = 1
if (right <= 115) then bits.1 = 1 : bits.0 = 0
If (right => 135) then bits.3 = 1 : bits.2 = 0
If (left <= 115) then bits.5 = 1 : bits.4 = 0
If (left => 135) then bits.7 = 1 : bits.6 = 0
transmit
goto loop


RX end....
In brief:
if bits.7 = bits.6 then bitserror 'bit pairs shouldn't be equal
if bits.5 = bits.4 then bitserror
if bits.3 = bits.2 then bitserror
if bits.1 = bits.0 then bitserror

'Stop '--------------------------------$69 = 01 10 10 01
'Leftwheel =stop : Rightwheel= CCW '--- $A6 = 10 10 01 10
'Leftwheel =stop : Rightwheel= CW '----- $96 = 10 01 01 10
'Leftwheel =CCW : Rightwheel= stop '---- $9a = 10 01 10 10
'Leftwheel =CW : Rightwheel= stop '----- $A5 = 10 10 01 01
'Leftwheel =CW : Rightwheel= CW '---- $66 = 01 10 01 10
'Leftwheel =CW : Rightwheel= CCW '---- $56 = 01 01 01 10
'Leftwheel =CCW : Rightwheel= CW '---- $5a = 01 01 10 10
'Leftwheel =CCW : Rightwheel= CCW '---- $65 = 01 10 01 01

And at the receiver end, the receiver code wouldn't actuate a motor until receiving a few correct codes in a row (a one time code wouldn't trip the motors into running).

Just a quick thought I had...