SHARE
TWEET

BMS version 1.2

EastmanLG Apr 23rd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --BMS Mainframe(2019)
  2. --Version 1.1
  3. --Logan Eastman
  4. --The best program written, probably ever.
  5.  
  6. --Set Automode
  7. local AutoBMS = true;
  8. --Set Refresh rate
  9. local refreshRate = 5;
  10.  
  11. --Time thresholds to determine day/night sequencing
  12. local nightTimeStart = 18 --24H Format
  13. local dayTimeStart = 5 --24H Format
  14.  
  15.  
  16. -- Set side IO
  17. -- Each light wire should have a side and name like the ones below.
  18. local buildingLights = "top"
  19. local buildingLightsName = "Lab Lights"
  20.  
  21. local OutsideLights = "right"
  22. local outsideLightsName = "Ground Lights"
  23.  
  24.  
  25. -- FUNCTIONS ------------------------------------------------------------------------
  26.  
  27. function getState(input)
  28.     return rs.getInput(input)
  29. end
  30.  
  31. function setState(output, state)
  32.     rs.setOutput(output, state)
  33. end
  34.  
  35. function printState(input, inputName)
  36.     if(getState(input) == true) then --If lights are on
  37.         print(inputName + ":\t ON")
  38.     else --Lights are off
  39.         print(inputName + ":\t OFF")
  40.     end
  41.  
  42.  
  43. function Day() --Gets whether it is day or night based on user thresholds.
  44.     local time = os.time
  45.  
  46.     if(time > dayTimeStart and time < nightTimeStart) then --If the time is between the defined Day/Night times, we know it is day.
  47.         return true --daytime
  48.     else
  49.         return false --Nighttime
  50.     end
  51. end
  52.  
  53. function autoDayLights(lights, lightsName, onDuringNight)
  54.     --Lights ON during NIGHT
  55.     if(Day() and onDuringNight == true) then -- It's day and lights should be on during night
  56.         if(getState(lights) == true) then --Turn off lights if on
  57.             setOutput(lights, false)
  58.             printState(lights, lightsName)
  59.         end
  60.     elseif(not Day() and onDuringNight == true) then -- It's night and lights should be on during night
  61.         if(getState(lights) == false) then --Turn On lights if Off
  62.             setOutput(lights, true)
  63.             printState(lights, lightsName)
  64.         end
  65.     --END Lights ON during NIGHT
  66.  
  67.     --Lights ON during DAY
  68.     elseif(Day() and onDuringNight == false) then -- It's day and lights should be on during day
  69.         if(getState(lights) == false) then --Turn On lights if Off
  70.             setOutput(lights, true)
  71.             printState(lights, lightsName)
  72.         end
  73.     elseif(not Day() and onDuringNight == false) then -- It's night and lights should be on during day
  74.         if(getState(lights) == true) then --Turn Off lights if On
  75.             setOutput(lights, false)
  76.             printState(lights, lightsName)
  77.         end
  78.     end
  79.     --END Lights ON during day
  80. end
  81.  
  82. -- LOOP -----------------------------------------------------------------------------
  83. while(true) do
  84.     if(AutoBMS) then
  85.         --Place Auto run code here
  86.         autoDayLights(buildingLights, buildingLightsName, true)
  87.         autoDayLights(outsideLights, outsideLightsName, true)
  88.         --END Auto Code
  89.     else
  90.         --Place code to run only when not in Auto
  91.  
  92.         --END Non-Auto Code
  93.     end
  94.     --Place code to run every loop
  95.  
  96.     --END Code Loop
  97.     os.sleep(refreshRate)
  98. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top