Advertisement
bobmarley12345

darkmattergeneratoronlinenotifier

Oct 10th, 2020 (edited)
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.16 KB | None | 0 0
  1. InputSignalDirection = "top"
  2. MonitorSide = "bottom"
  3. Monitor = peripheral.wrap(MonitorSide)
  4. RedstoneIOSide = "top"
  5. StopFunction = ""
  6.  
  7. function DrawText(xPos, yPos, text, textColour, backgroundColour)
  8.     Monitor.setBackgroundColor(backgroundColour)
  9.     Monitor.setTextColor(textColour)
  10.     Monitor.setCursorPos(xPos,yPos)
  11.     Monitor.write(text)
  12. end
  13.  
  14. function FillBackground(colour)
  15.     Monitor.setBackgroundColor(colour)
  16.     Monitor.clear()
  17. end
  18.  
  19. function DrawCenteredHorizontal(yPos, text, textColour, backgroundColour)
  20.     local monX, monY = Monitor.getSize()
  21.     local textLength = string.len(text)
  22.     local centerX = (monX / 2) - (textLength / 2)
  23.     DrawText(centerX, yPos, text, textColour, backgroundColour)
  24. end
  25.  
  26. function Draw()
  27.     while true do
  28.         local inputColours = redstone.getBundledInput(RedstoneIOSide)
  29.         local isActive = colours.test(inputColours, colours.white)
  30.         if (isActive) then
  31.             FillBackground(colours.green)
  32.             DrawCenteredHorizontal(2, "Dark Matter Generator", colours.white, colours.green)
  33.             DrawCenteredHorizontal(4, "ONLINE", colours.white, colours.green)
  34.         else
  35.             FillBackground(colours.red)
  36.             DrawCenteredHorizontal(2, "Dark Matter Generator", colours.white, colours.red)
  37.             DrawCenteredHorizontal(4, "OFFLINE", colours.white, colours.red)
  38.         end
  39.  
  40.         os.sleep(0.8)
  41.     end
  42. end
  43.  
  44. function WaitForMonitorTouch()
  45.     local event, side, x, y = os.pullEvent("monitor_touch")
  46.     --TouchX = x
  47.     --TouchY = y
  48.     StopFunction = "monTouch"
  49. end
  50.  
  51. function MonitorTouched()
  52.     local outputColours = redstone.getBundledOutput(RedstoneIOSide)
  53.  
  54.     if (colours.test(outputColours, colours.white)) then
  55.         redstone.setBundledOutput(RedstoneIOSide, outputColours - colours.white)
  56.     else
  57.         redstone.setBundledOutput(RedstoneIOSide, outputColours + colours.white)
  58.     end
  59.  
  60.     return
  61. end
  62.  
  63. function Main()
  64.     while true do
  65.         parallel.waitForAny(Draw, WaitForMonitorTouch)
  66.         if (StopFunction == "monTouch") then
  67.             StopFunction = "none"
  68.             MonitorTouched()
  69.         end
  70.     end
  71. end
  72.  
  73. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement