SHARE
TWEET

startup

a guest May 25th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mon = peripheral.find("monitor")
  2. rednet.open("right")
  3. cablePos = "bottom"
  4. etage = "ETAGE -2"
  5. dyh = 8
  6. dyb = 0
  7.  
  8. bg = colors.white
  9. text = colors.gray
  10.  
  11. function windowInit(win, bgColor, cursorX, cursorY, text)
  12.     win.setBackgroundColor(bgColor)
  13.     win.clear()
  14.     win.setCursorPos(cursorX, cursorY)
  15.     win.write(text)
  16. end
  17.  
  18. function monInit()
  19.     mon.setBackgroundColor(bg)
  20.     mon.setTextColor(text)
  21.     mon.clear()
  22.     mon.setTextScale(0.5)
  23.     mon.setCursorPos(5,1)
  24.     mon.write(etage)
  25.     if dyh>0 then
  26.         up = window.create(mon, 2, 3, 13, 10)
  27.         windowInit(up, colors.lightBlue, 4, 5, "ETAGE -1")
  28.     end
  29.     if dyb>0 then
  30.         down = window.create(mon, 2, 14, 13, 10)
  31.         windowInit(down, colors.orange, 4, 5, "ETAGE -3")
  32.     end
  33. end
  34.  
  35. function move(slp, dy, color)
  36.     local i = 0
  37.     while i<dy do
  38.         rs.setBundledOutput(cablePos, color)
  39.         sleep(slp)
  40.         rs.setBundledOutput(cablePos, 0)
  41.         sleep(slp)
  42.         i = i+1
  43.     end
  44. end
  45.  
  46. function touchedWindow(win, ex, ey)
  47.     local x, y = win.getPosition()
  48.     return ((ex>=x) and (ex<=x+12) and (ey>=y) and (ey<=y+9))
  49. end
  50.  
  51. function touchedButton(win)
  52.     win.setBackgroundColor(bg)
  53.     win.clear()
  54.     win.setVisible(false)
  55. end
  56.  
  57. monInit()
  58. while true do
  59.     local e, p1, p2, p3 = os.pullEvent()
  60.     if e=="monitor_touch" then
  61.         x = p2
  62.         y = p3
  63.         if (up~=nil) and touchedWindow(up, x, y) then
  64.             rednet.broadcast("elevator_left")
  65.             touchedButton(up)
  66.             move(0.4, dyh, colors.blue)
  67.             rednet.broadcast("", "elevator_left")
  68.             os.reboot()
  69.         end
  70.         if (down~=nil) and touchedWindow(down, x, y) then
  71.             rednet.broadcast("elevator_left")
  72.             touchedButton(down)
  73.             move(0.4, dyb, colors.orange)
  74.             rednet.broadcast("", "elevator_left")
  75.             os.reboot()
  76.         end
  77.     elseif e=="rednet_message" then
  78.         msg = p2
  79.         if msg=="elevator_left" then
  80.             if up~=nil then touchedButton(up) end
  81.             if down~=nil then touchedButton(down) end
  82.             rednet.receive("elevator_left", 10)
  83.             os.reboot()
  84.         end
  85.     end
  86. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top