SHARE
TWEET

startup

a guest Jan 22nd, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Config
  2. modemPos = "top"
  3. startLevel = 1000000
  4. stopLevel = 100000
  5.  
  6.  
  7.  
  8.  
  9. local gen = peripheral.wrap("right")
  10. rednet.open(modemPos)
  11. local powerSpace = "No message received"
  12.  
  13. function screen()
  14. term.clear()
  15. local title = "DiselGen2 Control by _TheSettler_"
  16. local l1 = "Unfilled energy capacity: "
  17. local xLen1 = string.len(title)
  18. local xLen2 = string.len(l1)
  19. local xLen3 = string.len(powerSpace)
  20. local xPos = (51-xLen1)/2
  21. term.setCursorPos(xPos, 2)
  22. print(title)
  23. local xPos = (51-xLen2)/2
  24. term.setCursorPos(xPos, 6)
  25. print(l1)
  26. local xPos = (51-xLen3)/2
  27. term.setCursorPos(xPos,7)
  28. print(powerSpace)
  29.  
  30. end
  31.  
  32. function getUpdate()
  33.   senderID, message, protocol = rednet.receive()
  34.   if protocol == "Settler" then
  35.     term.setCursorPos(1,12)
  36.     powerSpace = message  
  37.   end
  38. end
  39.  
  40. function isNumeric(value)
  41.   if tonumber(value) ~= nil then    
  42.     return true
  43.   else
  44.     return false
  45.   end
  46. end
  47.  
  48.  
  49. function getState()
  50.   if isNumeric(powerSpace) then
  51.     if powerSpace > startLevel then
  52.       status = "Activated"
  53.       term.setCursorPos(1,10)
  54.     end
  55.     if powerSpace < stopLevel then
  56.       status = "Deactivated"
  57.       term.setCursorPos(1,10)
  58.     end
  59.   else
  60.     status = "Error"
  61.   end
  62.    
  63.   if status == "Activated" then
  64.     gen.setEnabled(true)
  65.   else
  66.     gen.setEnabled(false)  
  67.   end
  68. end
  69.  
  70.  
  71.  
  72. while true do
  73.   screen()
  74.   getUpdate()
  75.   getState()
  76.   sleep(2)
  77. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top