注册 登录
编程论坛 Lua论坛

如何把这做成有延时100ms的

zzm参谋 发布于 2021-09-23 15:39, 1690 次点击
firstin1=0
buttonVar1=0xffff
colorflag=0
--------------------------------------------------------------------
function colortemp()    --色温

    lastbutton1 = Get_One_DataVal(0x0800)   

    if buttonVar1~=lastbutton1
    then
        buttonVar1=lastbutton1
        firstin1=1
        colorflag=1
    end
    if firstin1==1
    then

        if 0<=buttonVar1 and buttonVar1<20
        then
            local databuff1={0x28,0x01,0x00,0x12,0xA3,0x72,0x50}
            local databuff2={0x28,0x01,0x00,0x12,0xC3,0x01,0xFF}
            local databuff3={0x28,0x01,0x00,0x12,0xC1,0x08,0xFF}
            local databuff4={0x28,0x01,0x00,0x12,0xFF,0xE7,0xFF}
            local databuff5={0x28,0x01,0x00,0x12,0xC1,0x08,0xFF}
            local databuff6={0x28,0x01,0x00,0x12,0xFF,0xE2,0xFF}
            if colorflag==1
            then
                SendUartData(databuff1,7)
            elseif colorflag==2
            then
                SendUartData(databuff2,7)
            elseif colorflag==3
            then
                SendUartData(databuff3,7)
            elseif colorflag==4
            then
                SendUartData(databuff4,7)
            elseif colorflag==5
            then
                SendUartData(databuff5,7)
            elseif colorflag==6
            then
                SendUartData(databuff6,7)
                firstin1=0
                colorflag=0
            end     
        elseif 20<=buttonVar1 and buttonVar1<40
        then
            local databuff1={0x28,0x01,0x00,0x12,0xA3,0x1D,0xFB}
            local databuff2={0x28,0x01,0x00,0x12,0xC3,0x01,0xFF}
            local databuff3={0x28,0x01,0x00,0x12,0xC1,0x08,0xFF}
            local databuff4={0x28,0x01,0x00,0x12,0xFF,0xE7,0xFF}
            local databuff5={0x28,0x01,0x00,0x12,0xC1,0x08,0xFF}
            local databuff6={0x28,0x01,0x00,0x12,0xFF,0xE2,0xFF}
            if colorflag==1
            then
                SendUartData(databuff1,7)
            elseif colorflag==2
            then
                SendUartData(databuff2,7)
            elseif colorflag==3
            then
                SendUartData(databuff3,7)
            elseif colorflag==4
            then
                SendUartData(databuff4,7)
            elseif colorflag==5
            then
                SendUartData(databuff5,7)
            elseif colorflag==6
            then
                SendUartData(databuff6,7)
                firstin1=0
                colorflag=0
            end
        elseif 40<=buttonVar1 and buttonVar1<60
        then
            local databuff1={0x28,0x01,0x00,0x12,0xA3,0xDD,0xBB}
            local databuff2={0x28,0x01,0x00,0x12,0xC3,0x00,0xFE}
            local databuff3={0x28,0x01,0x00,0x12,0xC1,0x08,0xFF}
            local databuff4={0x28,0x01,0x00,0x12,0xFF,0xE7,0xFF}
            local databuff5={0x28,0x01,0x00,0x12,0xC1,0x08,0xFF}
            local databuff6={0x28,0x01,0x00,0x12,0xFF,0xE2,0xFF}
            if colorflag==1
            then
                SendUartData(databuff1,7)
            elseif colorflag==2
            then
                SendUartData(databuff2,7)
            elseif colorflag==3
            then
                SendUartData(databuff3,7)
            elseif colorflag==4
            then
                SendUartData(databuff4,7)
            elseif colorflag==5
            then
                SendUartData(databuff5,7)
            elseif colorflag==6
            then
                SendUartData(databuff6,7)
                firstin1=0
                colorflag=0
            end

        elseif 60<=buttonVar1 and buttonVar1<80
        then
            local databuff1={0x28,0x01,0x00,0x12,0xA3,0xC7,0xA5}
            local databuff2={0x28,0x01,0x00,0x12,0xC3,0x00,0xFE}
            local databuff3={0x28,0x01,0x00,0x12,0xC1,0x08,0xFF}
            local databuff4={0x28,0x01,0x00,0x12,0xFF,0xE7,0xFF}
            local databuff5={0x28,0x01,0x00,0x12,0xC1,0x08,0xFF}
            local databuff6={0x28,0x01,0x00,0x12,0xFF,0xE2,0xFF}
            if colorflag==1
            then
                SendUartData(databuff1,7)
            elseif colorflag==2
            then
                SendUartData(databuff2,7)
            elseif colorflag==3
            then
                SendUartData(databuff3,7)
            elseif colorflag==4
            then
                SendUartData(databuff4,7)
            elseif colorflag==5
            then
                SendUartData(databuff5,7)
            elseif colorflag==6
            then
                SendUartData(databuff6,7)
                firstin1=0
                colorflag=0
            end

        elseif 80<=buttonVar1 and buttonVar1<=100
        then
            local databuff1={0x28,0x01,0x00,0x12,0xA3,0x99,0x77}
            local databuff2={0x28,0x01,0x00,0x12,0xC3,0x00,0xFE}
            local databuff3={0x28,0x01,0x00,0x12,0xC1,0x08,0xFF}
            local databuff4={0x28,0x01,0x00,0x12,0xFF,0xE7,0xFF}
            local databuff5={0x28,0x01,0x00,0x12,0xC1,0x08,0xFF}
            local databuff6={0x28,0x01,0x00,0x12,0xFF,0xE2,0xFF}
            if colorflag==1
            then
                SendUartData(databuff1,7)
            elseif colorflag==2
            then
                SendUartData(databuff2,7)
            elseif colorflag==3
            then
                SendUartData(databuff3,7)
            elseif colorflag==4
            then
                SendUartData(databuff4,7)
            elseif colorflag==5
            then
                SendUartData(databuff5,7)
            elseif colorflag==6
            then
                SendUartData(databuff6,7)
                firstin1=0
                colorflag=0
            end
 
        end

    end
    colorflag=colorflag+1
   
end

0 回复
1