Lua语言:
gpio.mode(4,gpio.OUTPUT)
gpio.mode(2,gpio.OUTPUT)
gpio.write(4,1)
ReadData=""
ReadDataCopy=""
ReadCnt=0
ReadCntt =0
tmr.alarm(2, 5, 1, function()
if ReadCnt ~= 0 then
if ReadCnt == ReadCntt then
ReadCnt = 0
ReadCntt = 0
ReadDataCopy = ReadData
ReadData = ""
if ReadDataCopy == "++H" then
gpio.write(2,1)
end
if ReadDataCopy == "++L" then
gpio.write(2,0)
end
else
ReadCntt = ReadCnt
end
end
end)
tmr.alarm(1, 2000, 0, function()
uart.on("data", 0,function(Revdata)
ReadData = ReadData..Revdata
ReadCnt = ReadCnt + 1
end, 0)
end)
51_C语言:
转:https://www.cnblogs.com/yangfengwu/p/7520260.html