Advertisement
Guest User

startup

a guest
Apr 24th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.46 KB | None | 0 0
  1. shell.run("bg")
  2. os.loadAPI("button")
  3. term.clear()
  4. m = peripheral.wrap("monitor_1")
  5. m2 = peripheral.wrap("monitor_2")
  6. cell = peripheral.wrap("tile_blockcapacitorbank_name_0")
  7. m.clear()
  8. m2.clear()
  9.  
  10. function filltable()
  11.   m.clear()
  12.   button.clearTable()
  13.   button.screen()
  14.   sleep(0.2)
  15.   if page == 1 then
  16.     button.clearTable()
  17.     sleep(0.2)
  18.     button.setTable("Energy",statef," ",2,9,2,4)
  19.     button.setTable("Time",time," ",2,9,6,8)
  20.   elseif page == 2 then
  21.     button.setTable("Day",sday," ",2,8,2,4)
  22.     button.setTable("Night",snight," ",2,8,6,8)
  23.     button.setTable("Back",start," ",38,44,18,20)
  24.   end
  25. end
  26.  
  27. function getClick()
  28.   event,side,x,y = os.pullEvent("monitor_touch")
  29.   button.checkxy(x,y)
  30. end
  31.  
  32. function statef()
  33.   button.toggleButton("Energy")
  34.   if a == true then
  35.     rs.setOutput("back",false)
  36.     a = false
  37.   else
  38.     rs.setOutput("back",true)
  39.     a = true
  40.   end
  41. end
  42.  
  43. function start()
  44. page = 1
  45. button.clearTable()
  46. a = false
  47. x = true
  48. rs.setOutput("back",false)
  49. --filltable()
  50. --button.screen()
  51. start2()
  52. sleep(2)
  53. end
  54.  
  55. function start2()
  56. page = 1
  57. filltable()
  58. button.screen()
  59. if x == true then
  60.   x = false
  61.   button.toggleButton("Energy")
  62. end
  63. loop = true
  64. parallel.waitForAny(
  65.   function()
  66.     while loop do
  67.       getClick()
  68.       sleep(0.2)
  69.     end
  70.   end,
  71.   function()
  72.     while loop do
  73.       if a == false then
  74.         e = cell.getEnergyStored()
  75.         m.setCursorPos(11,3)
  76.         m.write(e)
  77.         sleep(0.2)
  78.       else
  79.         m.setCursorPos(11,3)
  80.         m.write("          ")
  81.         sleep(0.2)
  82.       end
  83.     end
  84.   end
  85. )
  86. end
  87.  
  88. start()
  89.  
  90. function time()
  91.   page = 2
  92.   sleep(0.2)
  93.   button.clearTable()
  94.   button.screen()
  95.   sleep(0.2)
  96.   filltable()
  97.   button.screen()
  98.   parralel.waitForAny(
  99.     function()
  100.       t = os.time()
  101.       m.setCursorPos()
  102.       m.write("Current time: "..t)
  103.       sleep(0.2)
  104.     end,
  105.     function()
  106.       getClick()
  107.     end
  108.   )
  109. end
  110.  
  111. function sday()
  112.   button.flash("Day")
  113.   if t <= 6 then
  114.     rs.setOutput("left",true)
  115.     sleep(100)
  116.     rs.setOutput("left",false)
  117.   elseif time >= 18 then
  118.     rs.setOutput("left",true)
  119.     sleep(20)
  120.     rs.setOutput("left",false)
  121.   end  
  122. end    
  123.  
  124. function snight()  
  125.   button.flash("Night")
  126.   if t >= 12 and t <= 18 then
  127.     rs.setOutput("left",true)
  128.     sleep(10)
  129.     rs.setOutput("left",false)
  130.   elseif t >= 6 and t <= 12 then
  131.     rs.setOutput("left",true)
  132.     sleep(20)
  133.     rs.setOutput("left",false)
  134.   end
  135. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement