local M = {}
local timer = 0
local timer2 = 0
local timer3 = 0
local cycleComplete = 0
local cycleStarting = 0

local function onInit()
    electrics.values["signal_L_0"] = 0
    electrics.values["signal_L_1"] = 0
    electrics.values["signal_L_2"] = 0
    electrics.values["signal_L_3"] = 0
    electrics.values["signal_L_4"] = 0
    electrics.values["signal_L_5"] = 0
    electrics.values["signal_L_6"] = 0
    electrics.values["signal_L_7"] = 0
    electrics.values["signal_L_8"] = 0
    electrics.values["signal_L_9"] = 0
    electrics.values["signal_L_10"] = 0
    electrics.values["signal_L_11"] = 0
    electrics.values["signal_L_12"] = 0
    electrics.values["signal_L_13"] = 0
    electrics.values["signal_L_14"] = 0
    electrics.values["signal_L_15"] = 0
    electrics.values["signal_L_16"] = 0
    electrics.values["signal_L_17"] = 0
    electrics.values["signal_L_18"] = 0
    electrics.values["signal_L_19"] = 0
    electrics.values["signal_L_20"] = 0
    electrics.values["signal_L_21"] = 0
    electrics.values["signal_L_22"] = 0
    
    electrics.values["signal_R_0"] = 0
    electrics.values["signal_R_1"] = 0
    electrics.values["signal_R_2"] = 0
    electrics.values["signal_R_3"] = 0
    electrics.values["signal_R_4"] = 0
    electrics.values["signal_R_5"] = 0
    electrics.values["signal_R_6"] = 0
    electrics.values["signal_R_7"] = 0
    electrics.values["signal_R_8"] = 0
    electrics.values["signal_R_9"] = 0
    electrics.values["signal_R_10"] = 0
    electrics.values["signal_R_11"] = 0
    electrics.values["signal_R_12"] = 0
    electrics.values["signal_R_13"] = 0
    electrics.values["signal_R_14"] = 0
    electrics.values["signal_R_15"] = 0
    electrics.values["signal_R_16"] = 0
    electrics.values["signal_R_17"] = 0
    electrics.values["signal_R_18"] = 0
    electrics.values["signal_R_19"] = 0
    electrics.values["signal_R_20"] = 0
    electrics.values["signal_R_21"] = 0
    electrics.values["signal_R_22"] = 0

    timer2 = 0
    timer = 0
    timer3 = 0
    cycleStarting = 0
    cycleComplete = 0
end

local function onReset()
    electrics.values["signal_L_0"] = 0
    electrics.values["signal_L_1"] = 0
    electrics.values["signal_L_2"] = 0
    electrics.values["signal_L_3"] = 0
    electrics.values["signal_L_4"] = 0
    electrics.values["signal_L_5"] = 0
    electrics.values["signal_L_6"] = 0
    electrics.values["signal_L_7"] = 0
    electrics.values["signal_L_8"] = 0
    electrics.values["signal_L_9"] = 0
    electrics.values["signal_L_10"] = 0
    electrics.values["signal_L_11"] = 0
    electrics.values["signal_L_12"] = 0
    electrics.values["signal_L_13"] = 0
    electrics.values["signal_L_14"] = 0
    electrics.values["signal_L_15"] = 0
    electrics.values["signal_L_16"] = 0
    electrics.values["signal_L_17"] = 0
    electrics.values["signal_L_18"] = 0
    electrics.values["signal_L_19"] = 0
    electrics.values["signal_L_20"] = 0
    electrics.values["signal_L_21"] = 0
    electrics.values["signal_L_22"] = 0
    
    electrics.values["signal_R_0"] = 0
    electrics.values["signal_R_1"] = 0
    electrics.values["signal_R_2"] = 0
    electrics.values["signal_R_3"] = 0
    electrics.values["signal_R_4"] = 0
    electrics.values["signal_R_5"] = 0
    electrics.values["signal_R_6"] = 0
    electrics.values["signal_R_7"] = 0
    electrics.values["signal_R_8"] = 0
    electrics.values["signal_R_9"] = 0
    electrics.values["signal_R_10"] = 0
    electrics.values["signal_R_11"] = 0
    electrics.values["signal_R_12"] = 0
    electrics.values["signal_R_13"] = 0
    electrics.values["signal_R_14"] = 0
    electrics.values["signal_R_15"] = 0
    electrics.values["signal_R_16"] = 0
    electrics.values["signal_R_17"] = 0
    electrics.values["signal_R_18"] = 0
    electrics.values["signal_R_19"] = 0
    electrics.values["signal_R_20"] = 0
    electrics.values["signal_R_21"] = 0
    electrics.values["signal_R_22"] = 0
end

local function updateGFX(dt) 
    if electrics.values["signal_L"] == 1 then
        timer = timer + dt
        
        if timer >= 0.01 then
            electrics.values["signal_L_0"] = 1
        end
        if timer >= 0.0272 then
            electrics.values["signal_L_1"] = 1
        end
        if timer >= 0.0541 then
            electrics.values["signal_L_2"] = 1
        end
        if timer >= 0.081 then
            electrics.values["signal_L_3"] = 1
        end
        if timer >= 0.1079 then
            electrics.values["signal_L_4"] = 1
        end
        if timer >= 0.1348 then
            electrics.values["signal_L_5"] = 1
        end
        if timer >= 0.1617 then
            electrics.values["signal_L_6"] = 1
        end
        if timer >= 0.1886 then
            electrics.values["signal_L_7"] = 1
        end
        if timer >= 0.2155 then
            electrics.values["signal_L_8"] = 1
        end
        if timer >= 0.2424 then
            electrics.values["signal_L_9"] = 1
        end
        if timer >= 0.2693 then
            electrics.values["signal_L_10"] = 1
        end
        if timer >= 0.2962 then
            electrics.values["signal_L_11"] = 1
        end
        if timer >= 0.3231 then
            electrics.values["signal_L_12"] = 1
        end
        if timer >= 0.3500 then
            electrics.values["signal_L_13"] = 1
        end
        if timer >= 0.3769 then
            electrics.values["signal_L_14"] = 1
        end
        if timer >= 0.4038 then
            electrics.values["signal_L_15"] = 1
        end
        if timer >= 0.4307 then
            electrics.values["signal_L_16"] = 1
        end
        if timer >= 0.4576 then
            electrics.values["signal_L_17"] = 1
        end
        if timer >= 0.4845 then
            electrics.values["signal_L_18"] = 1
        end
        if timer >= 0.5114 then
            electrics.values["signal_L_19"] = 1
        end
        if timer >= 0.5383 then
            electrics.values["signal_L_20"] = 1
        end
        if timer >= 0.5652 then
            electrics.values["signal_L_21"] = 1
        end
        if timer >= 0.5921 then
            electrics.values["signal_L_22"] = 1
        end
        
    else
        electrics.values["signal_L_0"] = 0
        electrics.values["signal_L_1"] = 0
        electrics.values["signal_L_2"] = 0
        electrics.values["signal_L_3"] = 0
        electrics.values["signal_L_4"] = 0
        electrics.values["signal_L_5"] = 0
        electrics.values["signal_L_6"] = 0
        electrics.values["signal_L_7"] = 0
        electrics.values["signal_L_8"] = 0
        electrics.values["signal_L_9"] = 0
        electrics.values["signal_L_10"] = 0
        electrics.values["signal_L_11"] = 0
        electrics.values["signal_L_12"] = 0
        electrics.values["signal_L_13"] = 0
        electrics.values["signal_L_14"] = 0
        electrics.values["signal_L_15"] = 0
        electrics.values["signal_L_16"] = 0
        electrics.values["signal_L_17"] = 0
        electrics.values["signal_L_18"] = 0
        electrics.values["signal_L_19"] = 0
        electrics.values["signal_L_20"] = 0
        electrics.values["signal_L_21"] = 0
        electrics.values["signal_L_22"] = 0
        timer = 0    
    end
    
    if electrics.values["signal_R"] == 1 then
        timer2 = timer2 + dt
        
        if timer2 >= 0.01 then
            electrics.values["signal_R_0"] = 1
        end
        if timer2 >= 0.0272 then
            electrics.values["signal_R_1"] = 1
        end
        if timer2 >= 0.0541 then
            electrics.values["signal_R_2"] = 1
        end
        if timer2 >= 0.081 then
            electrics.values["signal_R_3"] = 1
        end
        if timer2 >= 0.1079 then
            electrics.values["signal_R_4"] = 1
        end
        if timer2 >= 0.1348 then
            electrics.values["signal_R_5"] = 1
        end
        if timer2 >= 0.1617 then
            electrics.values["signal_R_6"] = 1
        end
        if timer2 >= 0.1886 then
            electrics.values["signal_R_7"] = 1
        end
        if timer2 >= 0.2155 then
            electrics.values["signal_R_8"] = 1
        end
        if timer2 >= 0.2424 then
            electrics.values["signal_R_9"] = 1
        end
        if timer2 >= 0.2693 then
            electrics.values["signal_R_10"] = 1
        end
        if timer2 >= 0.2962 then
            electrics.values["signal_R_11"] = 1
        end
        if timer2 >= 0.3231 then
            electrics.values["signal_R_12"] = 1
        end
        if timer2 >= 0.3500 then
            electrics.values["signal_R_13"] = 1
        end
        if timer2 >= 0.3769 then
            electrics.values["signal_R_14"] = 1
        end
        if timer2 >= 0.4038 then
            electrics.values["signal_R_15"] = 1
        end
        if timer2 >= 0.4307 then
            electrics.values["signal_R_16"] = 1
        end
        if timer2 >= 0.4576 then
            electrics.values["signal_R_17"] = 1
        end
        if timer2 >= 0.4845 then
            electrics.values["signal_R_18"] = 1
        end
        if timer2 >= 0.5114 then
            electrics.values["signal_R_19"] = 1
        end
        if timer2 >= 0.5383 then
            electrics.values["signal_R_20"] = 1
        end
        if timer2 >= 0.5652 then
            electrics.values["signal_R_21"] = 1
        end
        if timer2 >= 0.5921 then
            electrics.values["signal_R_22"] = 1
        end
        
    else
        electrics.values["signal_R_0"] = 0
        electrics.values["signal_R_1"] = 0
        electrics.values["signal_R_2"] = 0
        electrics.values["signal_R_3"] = 0
        electrics.values["signal_R_4"] = 0
        electrics.values["signal_R_5"] = 0
        electrics.values["signal_R_6"] = 0
        electrics.values["signal_R_7"] = 0
        electrics.values["signal_R_8"] = 0
        electrics.values["signal_R_9"] = 0
        electrics.values["signal_R_10"] = 0
        electrics.values["signal_R_11"] = 0
        electrics.values["signal_R_12"] = 0
        electrics.values["signal_R_13"] = 0
        electrics.values["signal_R_14"] = 0
        electrics.values["signal_R_15"] = 0
        electrics.values["signal_R_16"] = 0
        electrics.values["signal_R_17"] = 0
        electrics.values["signal_R_18"] = 0
        electrics.values["signal_R_19"] = 0
        electrics.values["signal_R_20"] = 0
        electrics.values["signal_R_21"] = 0
        electrics.values["signal_R_22"] = 0
		
        timer2 = 0    
    end
end

M.onInit = onInit
M.onReset = onReset
M.updateGFX = updateGFX

return M