function m1010() -- pedel = Input#13 --srtart boton = Input#21 --light ========Output#30 local on=1 local light = mc.OSIG_OUTPUT30 local hsig = mc.mcSignalGetHandle(inst, light) mc.mcSignalSetState(hsig, 1) inst = mc.mcGetInstance(); dhs= mc.mcSignalWait(inst, mc.ISIG_INPUT21, 1, 200000); --wait first press on boton local state=1 local vacuum = 0 if (dhs == 0) then --in case the boton press first time mc.mcCntlSetLastError(inst, "first buton press"); local needChange=0 local i=1 local firstPedal=1 while i<500001 do local inst = mc.mcGetInstance() local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT13) local pedal = mc.mcSignalGetState(hsig) if (pedal == 1) then if(firstPedal==1) then firstPedal=0 mc.mcCntlSetLastError(inst, "pedal"); state=2 if(vacuum==0) then vacuum=1 else vacuum=0 state=1 end mc.mcCntlSetLastError(inst, string.format(vacuum)); end end if (pedal == 0) then if(firstPedal==0) then firstPedal=1 end end i=i+1 if(vacuum==0) then if(i==250000) then needChange =1 end end if(vacuum==1) then if(i==100000) then needChange =1 end if(i==200000) then needChange =1 end if(i==300000) then needChange =1 end if(i==400000) then needChange =1 end if(i==500000) then needChange =1 end end if(needChange==1) then if(on==1) then local light = mc.OSIG_OUTPUT30 local hsig = mc.mcSignalGetHandle(inst, light) mc.mcSignalSetState(hsig, 0) on=0 else local light = mc.OSIG_OUTPUT30 local hsig = mc.mcSignalGetHandle(inst, light) mc.mcSignalSetState(hsig, 1) on=1 end needChange=0 end if(i==500000) then i=1 end local inst = mc.mcGetInstance() local hsig2 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT21) local boton = mc.mcSignalGetState(hsig2) if (boton == 1) then if(state==2) then mc.mcCntlSetLastError(inst, "boton"); i=1000000 end end end end mc.mcCntlSetLastError(inst, "run"); local light = mc.OSIG_OUTPUT30 local hsig = mc.mcSignalGetHandle(inst, light) mc.mcSignalSetState(hsig, 0) end