国内综合精彩aⅤ无码不卡_日本少妇做爰全过程_欧美性爱在线播放免费_午夜?V日韩一区二区_免费a级毛片无码免费播放_成在人线av无码喷水_亚洲精品网站色视频_国产婷婷精品成人_老师撩起裙子让我桶的视频_秋霞影院国产

怎么用一個(gè)模塊控制兩個(gè)LED

作者:liu583501928 | 更新時(shí)間:2019-04-02 | 瀏覽量:1423

這是一個(gè)不錯(cuò)的想法...

評(píng)論:共6條

liu583501928 評(píng)論于:2019-04-02 23:48:12
照著kaiguan.lua改的,兩個(gè)倒是都能控制,不過(guò)LED1打開(kāi)關(guān)閉一次,設(shè)備就離線了,是我想法不對(duì)嗎?
--use sjson
_G.cjson = sjson
--modify DEVICEID INPUTID APIKEY
DEVICEID = "10xxx"

APIKEY = "88xxxxxx"

INPUTID = "8xxx"
host = host or "m.placeboworld.cn"
port = port or 8181
LED = 3
LED1 = 4


isConnect = false
gpio.mode(LED,gpio.OUTPUT)
gpio.mode(LED1,gpio.OUTPUT)
local function run()
local cu = net.createConnection(net.TCP)
cu:on("receive", function(cu, c)
print(c)
isConnect = true
r = cjson.decode(c)
if r.M == "say" then
if r.C == "play" then
gpio.write(LED, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn on!"})
cu:send( played.."\n" )
end

if r.C == "play1" then
gpio.write(LED1, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn on!"})
cu:send( play1ed.."\n" )
end

if r.C == "stop" then
gpio.write(LED, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn off!"})
cu:send( stoped.."\n" )
end

if r.C == "stop1" then
gpio.write(LED1, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn off!"})
cu:send( stop1ed.."\n" )
end
end
end)
cu:on('disconnection',function(scu)
cu = nil
isConnect = false
tmr.stop(1)
tmr.alarm(6, 5000, 0, run)
end)
cu:connect(port, host)
ok, s = pcall(cjson.encode, {M="checkin",ID=DEVICEID,K=APIKEY})
if ok then
print(s)
else
print("failed to encode!")
end
if isConnect then
cu:send(s.."\n")
end
tmr.alarm(1, 60000, 1, function()
if isConnect then
cu:send(s.."\n")
end
end)
end
run()
情.若隔至千里 評(píng)論于:2019-04-08 20:15:24
LED = 1
LED1 = 2
你試一試,D4好像是串口
zjnbzm 評(píng)論于:2019-04-11 16:40:05
改為以下就可
if r.M == "say" then
if r.C == "play" then
gpio.write(LED, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn on!"})
cu:send( played.."\n" )
end

if r.C == "play1" then
gpio.write(LED1, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="LED1 turn on!"})
cu:send( play1ed.."\n" )
end

if r.C == "stop" then
gpio.write(LED, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn off!"})
cu:send( stoped.."\n" )
end

if r.C == "stop1" then
gpio.write(LED1, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="LED1 turn off!"})
cu:send( stop1ed.."\n" )
end
douzs 評(píng)論于:2019-04-28 13:46:53
很厲害了,我的到現(xiàn)在還沒(méi)頭緒呢
面包不好吃 評(píng)論于:2019-07-02 06:16:10
我已經(jīng)成功用一個(gè)模塊控制 多路
405893594 回復(fù)于:2019-10-10 22:47:51
回復(fù) @面包不好吃:能不能發(fā)個(gè)程序上來(lái)
返回頂部