Anybody out there able to help?
Here is the TX side...
Code: Select all
from machine import Pin, UART, SPI,ADC
from time import sleep
#machine.freq(250000000)
direct=0
speed=0
uart = UART(1,115200, tx=Pin(4), rx=Pin(5))
led=Pin(25,Pin.OUT)
joy_y = ADC(Pin(27))
joy_x = ADC(Pin(26))
butA=Pin(15,Pin.IN, Pin.PULL_UP)
butB=Pin(14,Pin.IN, Pin.PULL_UP)
butC=Pin(13,Pin.IN, Pin.PULL_UP)
butD=Pin(12,Pin.IN, Pin.PULL_UP)
swA=Pin(11,Pin.IN, Pin.PULL_UP)
swB=Pin(10,Pin.IN, Pin.PULL_UP)
swC=Pin(9,Pin.IN, Pin.PULL_UP)
swD=Pin(8,Pin.IN, Pin.PULL_UP)
def map(x, in_min, in_max, out_min, out_max):
return int((x-in_min)*(out_max-out_min)/(in_max-in_min))
while True:
y=(joy_y.read_u16())
x=(joy_x.read_u16())
y_val=map(y,288,65535,0,255)
x_val=map(x,288,65535,0,255)
if(y_val>138 and x_val<138 and x_val>118):#Forward
direct=1
speed=map(y_val,138,255,0,255)
elif(y_val<118 and x_val>118 and x_val<138):#Reverse
direct=5
speed=map(y_val,118,0,0,255)
elif(y_val>138 and x_val<118):#Forward Left
direct=8
speed=map(y_val,138,255,0,255)
elif(y_val>138 and x_val>138):#Forward Right
direct=2
speed=map(y_val,138,255,0,255)
elif(y_val<118 and x_val<118):#Reverse Left
direct=6
speed=map(y_val,118,0,0,255)
elif(y_val<118 and x_val>138):#Reverse Right
direct=4
speed=map(y_val,118,0,0,255)
elif(x_val<118 and y_val>118 and y_val<138):#Left
direct=7
speed=map(x_val,118,0,0,255)
elif(x_val>138 and y_val>118 and y_val<138):#Right
direct=3
speed=map(x_val,138,255,0,255)
else:#Stop
direct=0
speed=0
Ba=butA.value()
Bb=butB.value()
Bc=butC.value()
Bd=butD.value()
Sa=swA.value()
Sb=swB.value()
Sc=swC.value()
Sd=swD.value()
potA=255
potB=103
joyA=217
joyB=163
lead=0
instruction=(lead,direct,speed,Ba,Bb,Bc,Bd,Sa,Sb,Sc,Sd,potA,potB,joyA,joyB)
command=str(instruction)
print(command)
uart.write(command)
uart.sendbreak()
led.value(1)
sleep(.1)
led.value(0)
sleep(.1)
and the RX side for reference...
Code: Select all
from machine import Pin, UART
from time import sleep
radio=UART(1,115200, tx=Pin(4), rx=Pin(5))
global speed
global direction
global butA
global butB
global butC
global swA
global swB
global swC
global swD
global potA
global potB
global potC
global potD
while True:
if radio.any():
info=str(radio.readline())
print(info)
(list(info))
command= (info.split(','))
print(command)
Thanks,