Advertisement
gunny576

Coil Monitor System

Apr 26th, 2020
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | None | 0 0
  1. --[[
  2. Author: Gunny576
  3. Date: 4/26
  4. Coil Monitor System CMS
  5.  
  6.  
  7. Usage: This program is to be run on a CC turtle with a wireless motem installed on the left side.
  8.         A coil is a ring of power cells given the following layout:
  9.           123
  10.         12x  4
  11.         11   5
  12.         10   6
  13.           987
  14.         power must flow from 12 down to 1, and from 1 out into the main energy line. the turtle is placed at x and will move up to 12.
  15. --]]
  16.  
  17. --Network Parameters, Channel is what the receiver should be listening to, TurtleID should be the channel you expect a reply from
  18. channel = 1
  19. turtleID = 1
  20.  
  21. --Coil settings and start point.
  22. coilMax = 12
  23. currentCell = 1
  24.  
  25. --Peripherial configuration
  26. cell = peripheral.wrap("front")
  27. modem = peripheral.wrap("left")
  28.  
  29. --internal Variables used
  30. data = {}
  31. charge=nil
  32.  
  33. function CheckSend ()
  34.     charge = cell.getEnergyStored()/500000
  35.     charge = string.format("%0.3f",charge)
  36.     charge = charge+0
  37.     --check if cell is fully charged, move on to next if it is.
  38.     if (charge== 100 and currentCell<coilMax) then
  39.         NextC()
  40.         CheckSend()
  41.         --recursive function break.
  42.         return
  43.     end
  44.     if (charge==0 and currentCell>1) then
  45.         LastC()
  46.         CheckSend()
  47.         --recursive function break.
  48.         return
  49.     end
  50.     --load data payload
  51.     charge=charge/100
  52.     charge=(charge/12+((currentCell-1)/12))
  53.     charge=charge*100
  54.     charge = string.format("%0.3f",charge)
  55.     charge = charge+0
  56.     data[0] = charge
  57.     data[2] = currentCell
  58.     data[1] = channel
  59.     modem.transmit(channel, turtleID, data)
  60. end
  61.  
  62. function NextC ()
  63.     turtle.turnLeft()
  64.     if turtle.forward() then
  65.         turtle.turnRight()
  66.     end
  67.     currentCell=currentCell+1
  68. end
  69.  
  70. function LastC ()
  71.     turtle.turnRight()
  72.     if turtle.forward() then
  73.         turtle.turnLeft()
  74.     end
  75.     currentCell=currentCell-1
  76.  
  77. end
  78.  
  79.  
  80. --Main Loop
  81.  
  82. while true do
  83.     CheckSend()
  84.     os.sleep(10)
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement