Advertisement
EastmanLG

BMS v1.9

Apr 22nd, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.07 KB | None | 0 0
  1. --BMS Mainframe(2019)
  2. --Version 1.9
  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. -- FUNCTIONS ------------------------------------------------------------------------
  16. function clearDisplay()
  17.     term.clear()
  18.     term.setCursorPos(1,1)
  19. end
  20.  
  21. function getState(input)
  22.     return rs.getInput(input)
  23. end
  24.  
  25. function setState(output, state)
  26.     rs.setOutput(output, state)
  27. end
  28.  
  29. function printState(input, inputName)
  30.     if(getState(input) == true) then --If lights are on
  31.         print(inputName .. ":\t ON")
  32.     else --Lights are off
  33.         print(inputName .. ":\t OFF")
  34.     end
  35. end
  36.  
  37.  
  38. function Day() --Gets whether it is day or night based on user thresholds.
  39.     local time = os.time()
  40.  
  41.     if(time > dayTimeStart and time < nightTimeStart) then --If the time is between the defined Day/Night times, we know it is day.
  42.         return true --daytime
  43.     else
  44.         return false --Nighttime
  45.     end
  46. end
  47.  
  48. function constantState(output, outputName, state)
  49.     setState(output, state)
  50.     printState(output, outputName)
  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.             setState(lights, false)
  58.         else
  59.             printState(lights, lightsName)
  60.             --print("It's day and lights should be on during night")
  61.         end
  62.     elseif(not Day() and onDuringNight == true) then -- It's night and lights should be on during night
  63.         if(getState(lights) == false) then --Turn On lights if Off
  64.             setState(lights, true)
  65.         else
  66.             printState(lights, lightsName)
  67.             --print("It's night and lights should be on during night")
  68.         end
  69.     --END Lights ON during NIGHT
  70.  
  71.     --Lights ON during DAY
  72.     elseif(Day() and onDuringNight == false) then -- It's day and lights should be on during day
  73.         if(getState(lights) == false) then --Turn On lights if Off
  74.             setState(lights, true)
  75.         else
  76.             printState(lights, lightsName)
  77.             --print("It's day and lights should be on during day")
  78.         end
  79.     elseif(not Day() and onDuringNight == false) then -- It's night and lights should be on during day
  80.         if(getState(lights) == true) then --Turn Off lights if On
  81.             setState(lights, false)
  82.         else
  83.             printState(lights, lightsName) 
  84.             --print("It's night and lights should be on during day")
  85.         end
  86.     else
  87.         print("Something is wrong.")
  88.     end
  89.     --END Lights ON during day
  90. end
  91.  
  92.  
  93.  
  94. -- LOOP -----------------------------------------------------------------------------
  95. while(true) do
  96.     if(AutoBMS) then
  97.         clearDisplay()
  98.         --Place Auto run code here
  99.         autoDayLights("top", "Lab Lights", true)
  100.         autoDayLights("right", "Outside Lights", true)
  101.         constantState("bottom", "Bottom Lights", true)
  102.         --END Auto Code
  103.     else
  104.         --Place code to run only when not in Auto
  105.  
  106.         --END Non-Auto Code
  107.     end
  108.     --Place code to run every loop
  109.    
  110.     --END Code Loop
  111.     os.sleep(refreshRate)
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement