Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --BMS Mainframe(2019)
- --Version 1.1
- --Logan Eastman
- --The best program written, probably ever.
- --Set Automode
- local AutoBMS = true;
- --Set Refresh rate
- local refreshRate = 5;
- --Time thresholds to determine day/night sequencing
- local nightTimeStart = 18 --24H Format
- local dayTimeStart = 5 --24H Format
- -- Set side IO
- -- Each light wire should have a side and name like the ones below.
- local buildingLights = "top"
- local buildingLightsName = "Lab Lights"
- local OutsideLights = "right"
- local outsideLightsName = "Ground Lights"
- -- FUNCTIONS ------------------------------------------------------------------------
- function getState(input)
- return rs.getInput(input)
- end
- function setState(output, state)
- rs.setOutput(output, state)
- end
- function printState(input, inputName)
- if(getState(input) == true) then --If lights are on
- print(inputName + ":\t ON")
- else --Lights are off
- print(inputName + ":\t OFF")
- end
- function Day() --Gets whether it is day or night based on user thresholds.
- local time = os.time
- if(time > dayTimeStart and time < nightTimeStart) then --If the time is between the defined Day/Night times, we know it is day.
- return true --daytime
- else
- return false --Nighttime
- end
- end
- function autoDayLights(lights, lightsName, onDuringNight)
- --Lights ON during NIGHT
- if(Day() and onDuringNight == true) then -- It's day and lights should be on during night
- if(getState(lights) == true) then --Turn off lights if on
- setOutput(lights, false)
- printState(lights, lightsName)
- end
- elseif(not Day() and onDuringNight == true) then -- It's night and lights should be on during night
- if(getState(lights) == false) then --Turn On lights if Off
- setOutput(lights, true)
- printState(lights, lightsName)
- end
- --END Lights ON during NIGHT
- --Lights ON during DAY
- elseif(Day() and onDuringNight == false) then -- It's day and lights should be on during day
- if(getState(lights) == false) then --Turn On lights if Off
- setOutput(lights, true)
- printState(lights, lightsName)
- end
- elseif(not Day() and onDuringNight == false) then -- It's night and lights should be on during day
- if(getState(lights) == true) then --Turn Off lights if On
- setOutput(lights, false)
- printState(lights, lightsName)
- end
- end
- --END Lights ON during day
- end
- -- LOOP -----------------------------------------------------------------------------
- while(true) do
- if(AutoBMS) then
- --Place Auto run code here
- autoDayLights(buildingLights, buildingLightsName, true)
- autoDayLights(outsideLights, outsideLightsName, true)
- --END Auto Code
- else
- --Place code to run only when not in Auto
- --END Non-Auto Code
- end
- --Place code to run every loop
- --END Code Loop
- os.sleep(refreshRate)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement