Advertisement
mikebald

SunDial

Jul 29th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if fs.exists("button") ~= true then
  2.     shell.run("pastebin get xujPVbgB button")
  3. end
  4.  
  5. local red = "right"
  6. local margin = 1
  7. local textScale = 2
  8. local maxRunningTicks = 400 -- 20 seconds
  9. local eveningStart = 19
  10. local morningStart = 6
  11. local morningEnd = 12
  12.  
  13. os.loadAPI("button")
  14. mon = peripheral.find("monitor")
  15. mon.setTextScale(textScale)
  16. x,y = mon.getSize()
  17. mon.clear()
  18. rs.setOutput(red, false)
  19.  
  20. function setTime(timeOfDay)
  21.     local runningTicks = 0
  22.     rs.setOutput(red, true)
  23.     print("setting time to: " .. timeOfDay)
  24.     if timeOfDay == "morning" then
  25.         -- wait for morning [6.00]
  26.         while(os.time() < morningStart or os.time() > morningEnd) do
  27.             sleep(.05) -- one tick
  28.             runningTicks = runningTicks + 1
  29.             if(runningTicks > maxRunningTicks) then break end -- Failsafe
  30.         end
  31.     elseif timeOfDay == "evening" then
  32.         -- wait for evening [18.541]
  33.         while(os.time() < eveningStart) do
  34.             sleep(.05) -- one tick
  35.             runningTicks = runningTicks + 1
  36.             if(runningTicks > maxRunningTicks) then break end -- Failsafe
  37.         end
  38.     end
  39.     print("done")
  40.     -- turn off
  41.     rs.setOutput(red, false)
  42. end
  43.  
  44. function Menu()    
  45.     button.clearTable()
  46.     button.setTable("Morning", setTime, "morning", 1, (x/2)-margin, 1, y)
  47.     button.setTable("Evening", setTime, "evening", (x/2)+margin, x, 1, y)
  48.     button.screen()
  49. end
  50.  
  51. while true do
  52.     Menu()
  53.     timerCode = os.startTimer(1)
  54.     local event, side, x, y
  55.     repeat
  56.         event, side, x, y = os.pullEvent()
  57.     until event == "monitor_touch"
  58.    
  59.     button.checkxy(x,y)
  60.    
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement