Advertisement
Guest User

demo

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