Klazam33

RedstoneController

Jan 14th, 2015 (edited)
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.95 KB | None | 0 0
  1. if not fs.exists("kapi") then
  2.  shell.run("label set KlazController")
  3.  shell.run("pastebin get Wa30xjVY kapi")
  4.  os.loadAPI("kapi")
  5. else
  6.  os.loadAPI("kapi")
  7. end
  8. -- Fine
  9.  
  10. if not fs.exists("side") then
  11. file = fs.open("side", "w")
  12.  
  13. directions = {"Front","Back", "Left", "Right", "Top", "Bottom"}
  14. l = #directions
  15. n = 1
  16. while true do
  17.  kapi.menu("Please select a direction to send the pulse:")
  18.  for i = 1, l, 1 do
  19.   if n == i then
  20.    print(">" .. directions[i] .. "<")
  21.   else
  22.    print(" " .. directions[i])
  23.   end
  24.  end
  25.  
  26.  keypress = kapi.keyread()
  27.  if keypress == keys.up then --Up Arrow
  28.   if n == 1 then
  29.    n = l
  30.   else
  31.    n = n - 1
  32.   end
  33.  elseif keypress == keys.down then --Down Arrow
  34.   if n == l then
  35.    n = 1
  36.   else
  37.    n = n + 1
  38.   end
  39.  elseif keypress == keys enter then --Enter key
  40.   kapi.clear()
  41.     if n == 1 then
  42.      file.write("front")
  43.     elseif n == 2 then
  44.      file.write("back")
  45.     elseif n == 3 then
  46.      file.write("left")
  47.     elseif n == 4 then
  48.      file.write("right")
  49.     elseif n == 5 then
  50.      file.write("top")
  51.     elseif n == 6 then
  52.      file.write("bottom")
  53.         end
  54.   os.reboot()
  55.   end
  56. end
  57. end
  58.  
  59. if not fs.exists("time") then
  60.  
  61. file = fs.open("time", "w")
  62.  
  63. times = {1,2,5,10,30,60}
  64. l = #times
  65. n = 1
  66. while true do
  67.  kapi.menu("Please select the interval between pulses (in seconds):")
  68.  for i = 1, l, 1 do
  69.   if n == i then
  70.    print(">" .. times[i] .. "<")
  71.   else
  72.    print(" " .. times[i])
  73.   end
  74.  end
  75.  
  76.  keypress = kapi.keyread()
  77.  if keypress == keys.up then --Up Arrow
  78.   if n == 1 then
  79.    n = l
  80.   else
  81.    n = n - 1
  82.   end
  83.  elseif keypress == keys.down then --Down Arrow
  84.   if n == l then
  85.    n = 1
  86.   else
  87.    n = n + 1
  88.   end
  89.  elseif keypress == keys.enter then --Enter key
  90.   kapi.clear()
  91.     if n == 1 then
  92.      file.write("1")
  93.     elseif n == 2 then
  94.      file.write("2")
  95.     elseif n == 3 then
  96.      file.write("5")
  97.     elseif n == 4 then
  98.      file.write("10")
  99.     elseif n == 5 then
  100.      file.write("30")
  101.     elseif n == 6 then
  102.      file.write("60")
  103.         end
  104.   os.reboot()
  105.   end
  106. end
  107. end
  108.  
  109. sideSave = fs.open("side","r")
  110. timeSave = fs.open("time","r")
  111. side = sideSave.readLine()
  112. time = tonumber(timeSave.readLine())
  113. kapi.menu("Klaz's Redstone Pulse Controller. \n\nYou are currently set to pulse in this direction: "..side.."\nThe length between pulses in seconds is: "..time.."\nPress enter to activate")
  114. x = kapi.keyread()
  115. if x == 28 then
  116.   kapi.clear()
  117.   kapi.menu("Klaz's Redstone Pulse Controller. \n\nYou are currently set to pulse in this direction: "..side.."\nThe length between pulses in seconds is: "..time.."\n\n This is active. please press and hold Ctrl+R to deactivate")
  118.  else
  119.   kapi.clear()
  120.   kapi.menu("Klaz's Redstone Pulse Controller. \n\nYou are currently set to pulse in this direction: "..side.."\nThe length between pulses in seconds is: "..time.."\n\n This is active. please press and hold Ctrl+R to deactivate")
  121. end
  122. while true do
  123.    
  124.  redstone.setOutput(side, true)
  125.  sleep(1)
  126.  redstone.setOutput(side, false)
  127.  sleep(time)  
  128.  
  129. end
Add Comment
Please, Sign In to add comment