local appName="LED-Control" local ctrlIdx --Index Lua Control local counter --aktueller Signalschrit local signal --aktuelles Signal local sLED --Schalterzustand LED-Schalter local sLED_alt --letzter Schalterzustand LED-Schalter local sSEQ --Schalterzustand Sequenzer Schalter local sigSEQ --aktuelles Signal des Sequenzers local automat = 0 --Sequenzer inaktiv, aktiv = 1 local maxcount --Anzahl der Lichtsequenzen local offset --Versatz für LED-Signal (wegen MUDLED-Modul) local sigoffset --Signallänge Offset local step --Schrittweite LED-Signal local switchLED --LED-Schalter local switchSEQ --Sequenzer Schalter local sOSEQ --Sequenzer Outputsignal local channelSEQ --Sequenzer Kanal -------------------------------------------------------------------- --Anfangswerte setzen- -------------------------------------------------------------------- local function dacapo() step = 2/maxcount offset = system.pLoad("offset", 10) sigoffset = offset/100 signal = -1 + sigoffset system.setControl(1,signal,0,0) counter = 1 signal = signal + step end -------------------------------------------------------------------- -- Bearbeitungsschleife -------------------------------------------------------------------- local function loop() sLED = system.getInputsVal(switchLED) if sLED ~= sLED_alt then if (sLED ~= -1) and (automat == 0) then system.playNumber(counter,0) end sLED_alt = sLED if (sLED >= 0) then system.setControl(1,signal,0,0) if (counter == maxcount) then counter = 1 signal = -1 + step + sigoffset else counter = counter +1 signal = signal + step if signal > 1 then signal = 1 end end else counter = 1 signal = - 1 + sigoffset system.setControl(1,signal,0,0) signal = signal + step end end sSEQ = system.getInputsVal(switchSEQ) --print (sSEQ) if (sSEQ == 1) then automat = 1 sigSEQ = system.getInputs(sOSEQ) --print (so6) system.setControl(1,sigSEQ,0,0) end if (sSEQ == - 1) and (automat == 1) then automat = 0 counter = 1 signal = - 1 + sigoffset system.setControl(1,signal,0,0) signal = signal + step end end --------------------------------------------------------- -- Funktionenen für Änderungen im Einstellmenü --------------------------------------------------------- local function maxcountChanged(value) maxcount=value system.pSave("maxcount",value) dacapo() end local function offsetChanged(value) offset=value system.pSave("offset",value) dacapo() end local function switchLEDChanged(value) switchLED=value system.pSave("switchLED",value) end local function switchSEQChanged(value) switchSEQ=value system.pSave("switchSEQ",value) end local function channelSEQChanged(value) channelSEQ=value system.pSave("channelSEQ",value) end ------------------------------------------------------------ -- Einstellmenü ------------------------------------------------------------ local function initForm(subform) form.addRow(2) form.addLabel({label="maxcount"}) form.addIntbox(maxcount,3,10,4,0,1,maxcountChanged) form.addRow(2) form.addLabel({label="offset"}) form.addIntbox(offset,0,20,10,0,1,offsetChanged) form.addRow(2) form.addLabel({label="SwitchLED"}) form.addInputbox(switchLED,true,switchLEDChanged) form.addRow(2) form.addLabel({label="SwitchSEQ"}) form.addInputbox(switchSEQ,true,switchSEQChanged) form.addRow(2) form.addLabel({label="ChannelSEQ"}) form.addIntbox(channelSEQ,1,14,6,0,1,channelSEQChanged) end -------------------------------------------------------------- -- Initialisierungsfunktion -------------------------------------------------------------- local function init() system.registerForm(1,MENU_MAIN,appName,initForm) maxcount = system.pLoad("maxcount",4) switchLED = system.pLoad("switchLED") switchSEQ = system.pLoad("switchSEQ") --print (switchLED, switchSEQ) channelSEQ = system.pLoad("channelSEQ",6) sOSEQ = "O"..channelSEQ --print (sOSEQ) ctrlIdx = system.registerControl(1, "Mudled Ctrl","C01") sLED_alt = system.getInputsVal(swichtLED) dacapo() end --------------------------------------------------------------- -- und ab zum API --------------------------------------------------------------- return { init=init, loop=loop, author="Hermann Eichner", version="10",name=appName}