Plazter

Template monitor with toggle background (touch)

Aug 27th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.80 KB | None | 0 0
  1. os.loadAPI("c")
  2. m = peripheral.find("monitor")
  3. ae = true
  4. plaz = true
  5. sus = true
  6. kezza = true
  7. def = colors.black  --Wished default color
  8. background = colors.lightGray -- The background color
  9. on = colors.lime -- "on" color
  10. off = colors.red -- "off" color
  11. toggle = true -- background or text colors
  12. -- off the current state
  13.  
  14. -- Off limits below here unless ur experienced. --
  15. rednet.open("right")
  16.  
  17. function colDef()
  18.   if toggle == true then
  19.     m.setBackgroundColor(background)
  20.   else
  21.     m.setTextColor(def)
  22.   end
  23. end
  24.  
  25. function colOn()
  26.   if toggle == true then
  27.     m.setBackgroundColor(on)
  28.   else
  29.     m.setTextColor(on)
  30.   end
  31. end
  32.  
  33. function colOff()
  34.   if toggle == true then
  35.     m.setBackgroundColor(off)
  36.   else
  37.     m.setTextColor(off)
  38.   end
  39. end
  40.  
  41.  
  42. function disp()
  43.   m.setCursorPos(1,1)
  44.   m.setTextColor(colors.black)
  45.   c.mWrite("AE:")
  46.   m.setCursorPos(1,2)
  47.   m.write("On/Off")
  48.   m.setCursorPos(1,4)
  49.   c.mWrite("Plaz")
  50.   m.setCursorPos(1,5)
  51.   c.mWrite(" Power:")
  52.   m.setCursorPos(1,6)
  53.   m.write("On/Off")
  54.   m.setCursorPos(1,8)
  55.   c.mWrite("Sus")
  56.   m.setCursorPos(1,9)
  57.   c.mWrite("Power:")
  58.   m.setCursorPos(1,10)
  59.   m.write("On/Off")
  60.   m.setCursorPos(1,12)
  61.   c.mWrite("Kezza")
  62.   m.setCursorPos(1,13)
  63.   c.mWrite("Power:")
  64.   m.setCursorPos(1,14)
  65.   m.write("On/Off")
  66. end
  67.  
  68.  
  69. function AEButt()
  70.   if x >= 1 and x < 8 and y == 2 then
  71.     print("Registered at: "..x.. "and at :".. y)
  72.     if ae == false then
  73.       ae = true
  74.       rednet.send(69,"on")
  75.       m.setCursorPos(1,2)
  76.       colOn()
  77.       m.write("On")
  78.       m.setCursorPos(4,2)
  79.       colDef()
  80.       m.write("Off")
  81.     elseif ae == true then
  82.       ae = false
  83.       rednet.send(69,"off")
  84.       m.setCursorPos(1,2)
  85.       colDef()
  86.       m.write("On")
  87.       colOff()
  88.       m.setCursorPos(4,2)
  89.       m.write("Off")
  90.     end
  91.   end
  92. end
  93.  
  94. function plazPower()
  95.   if x > 1 and x < 7 and y == 6 then
  96.     print("Reg: "..x .." ".. y)
  97.       if plaz == true then
  98.         plaz = false
  99.         rednet.send(71, "off")
  100.         print("Plaz Off")
  101.         m.setCursorPos(4,6)
  102.         colOff()
  103.         m.write("Off")
  104.         m.setCursorPos(1,6)
  105.         colDef()
  106.         m.write("On")
  107.       elseif plaz == false then
  108.         plaz = true
  109.         rednet.send(71, "on")
  110.         print("Plaz: ON")
  111.         m.setCursorPos(1,6)
  112.         colOn()
  113.         m.write("On")
  114.         m.setCursorPos(4,6)
  115.         colDef()
  116.         m.write("Off")
  117.       end
  118.    end
  119. end
  120.  
  121. function susPower()
  122.   if x > 1 and x < 7 and y == 10 then
  123.     print("Reg: ".. x.." "..y)
  124.       if sus == true then
  125.         sus = false
  126.         rednet.send(72, "off")
  127.         colOff()
  128.         m.setCursorPos(4,10)
  129.         m.write("Off")
  130.         colDef()
  131.         m.setCursorPos(1,10)
  132.         m.write("On")
  133.       elseif sus == false then
  134.         sus = true
  135.         rednet.send(72, "on")
  136.         colOn()
  137.         m.setCursorPos(1,10)
  138.         m.write("On")
  139.         colDef()
  140.         m.setCursorPos(4,10)
  141.         m.write("Off")
  142.      end
  143.   end
  144. end
  145.  
  146. function kezzaPower()
  147.   if x > 1 and x < 7 and y == 14 then
  148.     print("Reg: "..x.." "..y)
  149.       if kezza == false then
  150.         kezza = true
  151.         rednet.send(73, "on")
  152.         colOn()
  153.         m.setCursorPos(1,14)
  154.         m.write("On")
  155.         colDef()
  156.         m.setCursorPos(4,14)
  157.         m.write("Off")
  158.       elseif kezza == true then
  159.         kezza = false
  160.         rednet.send(73, "off")
  161.         colDef()
  162.         m.setCursorPos(1,14)
  163.         m.write("On")
  164.         m.setCursorPos(4,14)
  165.         colOff()
  166.         m.write("Off")
  167.       end
  168.   end
  169. end
  170.  
  171. m.setBackgroundColor(background)
  172. c.mClear()
  173. disp()
  174.  
  175. while true do
  176.   event, side, x, y = os.pullEvent("monitor_touch")
  177.   if x == 1 and x == 1 and y == 1 then
  178.     shell.run("edit but")
  179.   end
  180.   AEButt()
  181.   plazPower()
  182.   susPower()
  183.   kezzaPower()
  184.   sleep(0.5)
  185. end
Add Comment
Please, Sign In to add comment