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

實(shí)現(xiàn)外部一鍵開(kāi)關(guān)LED問(wèn)題,大神幫加消抖

作者:梵歌指紋密碼鎖批發(fā)零售 | 更新時(shí)間:2019-04-12 | 瀏覽量:1259

求大神幫忙加個(gè)消抖,非常感謝

DEVICEID = "8888"     
APIKEY   = "88818da" 
INPUTID  = "88888"     
host     = host or "m.placeboworld.cn"  --
port     = port or 8181
LED      = 6
LED1     = 5
LED2     = 2
gpio.mode(LED,gpio.OUTPUT)
gpio.mode(LED1,gpio.OUTPUT)
gpio.mode(LED2,gpio.OUTPUT)
gpio.mode(2,gpio.INT, gpio.PULLUP)
gpio.write(2, gpio.HIGH)
gpio.write(1, gpio.HIGH)
 local function ledTrg()
     local i = gpio.read(6)
     if (i == 1) then
         gpio.write(6, gpio.LOW)
    else
         gpio.write(6, gpio.HIGH)
    end
    end
local function run()
  local cu = net.createConnection(net.TCP)
  cu:on("receive", function(cu, c) 
    print(c)
    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 == "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
    end
  end)
  cu:on('disconnection',function(scu)
    cu = nil
    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
  cu:send(s.."\n")
  tmr.alarm(1, 60000, 1, function()
    cu:send(s.."\n")
  end)
end
gpio.trig(2, "low", ledTrg)
run()


評(píng)論:共0條

返回頂部