代碼讀不懂,誰能幫讀下原理,和用什么app控制小車。
function setwifi()
wifi.setmode(wifi.SOFTAP)
mac = wifi.ap.getmac()
local cfg = {}
cfg.ssid = "car_"..mac
cfg.pwd = "0123456789"
wifi.ap.config(cfg)
end
function setpwm()
pwm.setup(1,50,0)
pwm.setup(2,50,0)
pwm.setup(4,50,0)
pwm.setup(6,50,0)
pwm.setup(7,50,0)
pwm.start(1)
pwm.start(2)
pwm.start(4)
pwm.start(6)
pwm.start(7)
end
function motorpwm(index, value)
if value then
-- print (index,value)
pwm.setduty(index,value)
end
end
function setTcpServer()
sv = net.createServer(net.TCP)
sv:listen(8000,
function(c)
c:on("receive", function (c,pl)
--print(pl)
local t = sjson.decode(pl)
--for a,b in pairs(t) do
--print(a,b)
--end
motorpwm(1,t["p1"])
motorpwm(2,t["p2"])
motorpwm(4,t["p3"])
motorpwm(6,t["p4"])
motorpwm(7,t["p5"])
c:send("data received")
end)
c:send("hello car controler\n")
end
)
end
flag = 0;
wifi.eventmon.register(wifi.eventmon.AP_STACONNECTED, function(T)
print("\n\tAP - STATION CONNECTED".."\n\tMAC: "..T.MAC.."\n\tAID: "..T.AID)
if(flag == 0) then
setTcpServer()
flag = 1;
end
end)
setpwm()
setwifi()
uj5u.com熱心網友回復:
lua代碼,softap這段懂,后面看不懂了轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/119790.html
標籤:單片機/工控
上一篇:提示硬碟錯誤
下一篇:粵嵌開發板五子棋
