MastaC729

Disco Floor Master Computer Program

Aug 21st, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. function split(toSplit, pattern, results)
  2.  if not results then
  3.   results = {}
  4.  end
  5.  local start = 1
  6.  local splitStart, splitEnd = string.find(toSplit, pattern, start)
  7.  while splitStart do
  8.   table.insert(results, string.sub(toSplit, start, splitStart-1))
  9.   start = splitEnd+1
  10.   splitStart, splitEnd = string.find(toSplit, pattern, start)
  11.  end
  12.  table.insert(results, string.sub(toSplit, start))
  13.  return results
  14. end
  15.  
  16. function main()
  17.  rednet.open("bottom")
  18.  
  19.  local leave
  20.  
  21.  repeat
  22.   print("Enter the desired action.") --Format: state(on, off, allOn, allOff) row(1-15) color(1-15, only necessary if on or off state)
  23.   input = read()
  24.  
  25.   input_table = split(input, " ")
  26.   instructions = {}
  27.   instructions[1] = input_table[1]  -- Action
  28.   rowNumber = input_table[2]        -- Row number
  29.   instructions[2] = input_table[3]  -- Light number (color on cable)
  30.  
  31.   if instructions[1] == "allOn" or instructions[1] == "allOff" then
  32.     print("Performing "..instructions[1].." to "..rowNumber)
  33.   else
  34.     print("Turning "..instructions[1].." light number "..instructions[2].." in "..rowNumber)   
  35.   end
  36.  
  37.   rednet.broadcast(instructions, rowNumber)
  38.   print("Continue? Type false to stop")
  39.   leave = read()
  40.  until leave == "false"
  41.  
  42. end -- end main()
  43.  
  44. main()
Advertisement
Add Comment
Please, Sign In to add comment