Grauly

Laser Control v1

Apr 24th, 2020
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. local monitors = {
  2.     peripheral.wrap("top");
  3.     peripheral.wrap("monitor_0");
  4. }
  5.  
  6. local bool loading = false;
  7. local onColor = colors.yellow;
  8. local offColor = colors.blue;
  9. local defaultColor = colors.white;
  10.  
  11. --clears all monitors
  12. function clear()
  13.   for i=1, #monitors do
  14.     monitors[i].clear()
  15.     monitors[i].setTextColor(defaultColor)
  16.     monitors[i].setCursorPos(1,1)
  17.   end
  18. end
  19.  
  20. --goes to the next line for all monitors
  21. function nextline()
  22.   for i=1, #monitors do
  23.     local x,y = monitors[i].getCursorPos()
  24.     local y = y + 1
  25.     monitors[i].setCursorPos(1,y)
  26.   end
  27. end
  28.  
  29. --writes text on all monitors
  30. function writeText(text)
  31.   for i=1, #monitors do
  32.     monitors[i].write(text)
  33.   end
  34. end
  35.  
  36. --sets text color for all monitors
  37. function textColor(color)
  38.   for i=1, #monitors do
  39.     monitors[i].setTextColor(color)
  40.   end
  41. end
  42.  
  43. --sets background color for all monitors
  44. function backgroundColor(color)
  45.   for i=1, #monitors do
  46.     monitors[i].setBackgroundColor(color)
  47.   end
  48. end
  49.  
  50.  
  51. function routine()
  52.     if loading == true then
  53.         backgroundColor(onColor);
  54.         rs.setOutput("back",false);
  55.     else
  56.         backgroundColor(offColor);
  57.         rs.setOutput("back",true);
  58.     end
  59.     for i=1, #monitors do
  60.         clear();
  61.         local x,y = monitors[i].getSize();
  62.         y = math.floor(y/2);
  63.         x = math.floor(x/2);
  64.         if loading == true then
  65.             x = x -3;
  66.             monitors[i].setTextColor(defaultColor);
  67.             monitors[i].setCursorPos(x,y);
  68.             monitors[i].write("Charging");
  69.         else
  70.             x = x -1;
  71.             monitors[i].setTextColor(defaultColor);
  72.             monitors[i].setCursorPos(x,y);
  73.             monitors[i].write("Idle");
  74.         end
  75.     end
  76. end
  77.  
  78. while true do
  79.     local timer = os.startTimer(1)
  80.     local event,a1,a2,a3 = os.pullEvent()
  81.     if event == "timer" then
  82.         routine()
  83.     elseif event == "monitor_touch" then
  84.         routine()
  85.         local x = a2;
  86.         local y = a3;
  87.         loading = not loading;
  88.     end
  89. end
Advertisement
Add Comment
Please, Sign In to add comment