Advertisement
Guest User

demo

a guest
Apr 26th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. os.loadAPI("button")
  2. m = peripheral.wrap("right")
  3. m.clear()
  4.  
  5. local enabled = false
  6. local count = 0
  7. local dir = 0
  8.  
  9. function pulse(color)
  10.     rs.setBundledOutput("back", color)
  11.     sleep(1)
  12.     rs.setBundledOutput("back", 0)
  13. end
  14.  
  15. local function getDir()
  16.   if dir == 1 then
  17.     return "Forward"
  18.   elseif dir == 2 then
  19.     return "Backward"
  20.   elseif dir == 3 then
  21.     return "Left"
  22.   elseif dir == 4 then
  23.     return "Right"
  24.   else
  25.     return "None"
  26.   end
  27. end
  28.    
  29. function status()
  30.   if enabled then m.setBackgroundColor(colors.green)
  31.   else m.setBackgroundColor(colors.red) end
  32.    
  33.   m.setCursorPos(2,2)
  34.   m.write("                           ")
  35.   m.setCursorPos(2,3)
  36.   m.write("                           ")
  37.   m.setCursorPos(2,4)
  38.   m.write("                           ")
  39.  
  40.   w,h = m.getSize()
  41.  
  42.   if enabled then
  43.     m.setCursorPos((w-string.len("Status : Enabled"))/2+1, 2)
  44.     m.write("Status : Enabled")
  45.   else
  46.     m.setCursorPos((w-string.len("Status : Disabled"))/2+1, 2)
  47.     m.write("Status : Disabled")
  48.   end
  49.  
  50.   m.setCursorPos((w-string.len("Count : "..count))/2+1, 3)
  51.   m.write("Count : "..count)
  52.  
  53.   m.setCursorPos((w-string.len("Direction : "..getDir(dir)))/2+1, 4)
  54.   m.write("Direction : "..getDir(dir))
  55. end
  56.  
  57. function fillTable()
  58.    button.setTable("Forward", forward, 10,20,6,6)
  59.    button.setTable("Left", left, 2,12,8,8)
  60.    button.setTable("Right", right, 18,28,8,8)
  61.    button.setTable("Back", back, 10,20,10,10)
  62.    button.screen()
  63. end
  64.  
  65. function getClick()
  66.    event,side,x,y = os.pullEvent("monitor_touch")
  67.    button.checkxy(x,y)
  68. end
  69.  
  70. function forward()
  71.    button.toggleButton("Forward")
  72.    enabled = true
  73.    dir = 1
  74.    count = 10
  75.    
  76.    while count > 0 do
  77.      pulse(colors.red)
  78.    
  79.      count = count - 1
  80.      status()
  81.      sleep(3)
  82.    end
  83.    
  84.    button.toggleButton("Forward")
  85.    enabled = false
  86.    dir = 0
  87.    
  88.    status()
  89. end
  90.  
  91. function back()
  92.    button.toggleButton("T2")
  93.    print("Test2")
  94. end
  95.  
  96. function test3()
  97.    print("Test3")
  98. end
  99.  
  100. function test4()
  101.    print("Test4")
  102. end
  103.  
  104. fillTable()
  105. status()
  106.  
  107. while true do
  108.    getClick()
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement