thatparadox

sunDial

Apr 17th, 2015
319
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mon=peripheral.find("monitor")
  2. red = "top"
  3. x,y = mon.getSize()
  4.  
  5. if fs.exists("dialImage") ~= true then
  6.   shell.run("pastebin get iPTy3ePs dialImage")
  7. end
  8.  
  9. if fs.exists("buttonPress") then
  10.   file = fs.open("buttonPress", "r")
  11.   buttonPress = file.readAll()
  12.   file.close()
  13. end
  14.  
  15. term.redirect(mon)
  16. image = paintutils.loadImage("dialImage")
  17. paintutils.drawImage(image,1,1)
  18. term.redirect(term.native())
  19.  
  20. while true do
  21.   os.startTimer(3)
  22.   event, param1, param2, param3 = os.pullEvent()
  23.   print(event)
  24.   if event == "timer" then
  25.     sleep(0.05)
  26.   elseif event == "monitor_touch" then
  27.     print("touched")
  28.     if param2 < x/3 and param3 < y/2 then
  29.       userClick = 1
  30.     elseif param2 > x/3 and param2 < x/3*2 and param3 < y/2 then
  31.       userClick = 2
  32.     elseif param2 > x/3*2 and param3 < y/2 then
  33.       userClick = 3
  34.     elseif param2 < x/3 and param3 > y/2 then
  35.       userClick = 4
  36.     elseif param2 > x/3 and param2 < x/3*2 and param3 > y/2 then
  37.       userClick = 5
  38.     elseif param2 > x/3*2 and param3 > y/2 then
  39.       userClick = 6
  40.     end
  41.     file = fs.open("buttonPress", "w")
  42.     file.write(buttonPress)
  43.     file.close()
  44.     print(userClick)
  45.   end
  46.   if userClick == 1 then
  47.     if os.time() > 6 or os.time() < 5 then
  48.       rs.setOutput(red, true)
  49.     else
  50.       rs.setOutput(red,false)
  51.       userClick = 0
  52.     end
  53.   elseif userClick == 2 then
  54.     if os.time() > 17 or os.time() < 6 then
  55.       print("night")
  56.       rs.setOutput(red, true)
  57.     else
  58.       print("day")
  59.       rs.setOutput(red,false)
  60.     end
  61.   elseif userClick == 3 then
  62.     if os.time() > 19 or os.time() < 18 then
  63.       rs.setOutput(red, true)
  64.     else
  65.       rs.setOutput(red,false)
  66.       userClick = 0
  67.     end
  68.   elseif userClick == 4 then
  69.     if redstone.getAnalogInput("left") == 15 and os.time() > 23 then
  70.       rs.setOutput(red, false)
  71.       userClick = 0
  72.     else
  73.       rs.setOutput(red, true)
  74.     end
  75.   elseif userClick == 5 then
  76.     if os.time() < 17 and os.time() > 5 then
  77.       rs.setOutput(red, true)
  78.     else
  79.       rs.setOutput(red,false)
  80.     end
  81.   elseif userClick == 6 then
  82.     if redstone.getAnalogInput("right") == 15 and os.time() > 18 then
  83.       rs.setOutput(red, false)
  84.       userClick = 0
  85.     else
  86.       rs.setOutput(red, true)
  87.     end
  88.   end
  89. end
RAW Paste Data