GamearooCodes

Untitled

May 1st, 2023
1,138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. local component = require("component");
  2.  
  3. local redlight = component.traffic_light_card;
  4. local os = require("os")
  5. local term = require("term")
  6.  
  7. local thread = require("thread")
  8.  
  9. local m = component.modem -- get primary modem component
  10. local sides = require("sides")
  11. local computer = require("computer")
  12.  
  13. local colors = require("colors")
  14. m.setWakeMessage("start")
  15. m.broadcast(123, "on")
  16. os.sleep(1)
  17. m.open()
  18.  
  19. local loop3 = thread.create(function()
  20.   while true do
  21.     local name, receiver, sender, port, distance, on = computer.pullSignal()
  22.     if name == "modem_message" then
  23.       if(on == "stop") then
  24.         m.broadcast(123, 1,1,1 , "OFF")
  25.        
  26.         computer.shutdown(false)
  27.       end
  28.       if(on == "restart") then
  29.         m.broadcast(123, 1,1,1 , "OFF")
  30.        
  31.         computer.shutdown(true)
  32.       end
  33.    
  34.     end
  35.  
  36.     end
  37.     end)
  38.  
  39. term.clear()
  40. print("Traffic lights are starting! Lights are in flash mode")
  41. m.broadcast(123, colors.cyan, 200, sides.back)
  42. os.sleep(60);
  43. term.clear()
  44. print("Traffic lights are starting all lights are red!")
  45. m.broadcast(123, 3, 200, sides.back)
  46. os.sleep(1)
  47. m.broadcast(123, 3, 0, sides.back)
  48. os.sleep(8)
  49.  
  50.  
  51.  
  52. function sleep(n)
  53.     os.sleep(n)
  54.   end
  55. console = "East Left"
  56.   time = os.date("*t")
  57.   cycledtime = time.hour .. ":" .. time.min
  58. local loop1 = thread.create(function()
  59.     while true  do
  60.    
  61.       time2 = os.date("*t")
  62.       term.clear()
  63.       print("Time Cycled: " .. cycledtime)
  64.       print("Current Time: " .. time2.hour .. ":" .. time2.min)
  65.       print("energy:" .. computer.energy())
  66.       if(computer.energy() <= 1489) then
  67.         m.broadcast(123, 1,1,1 , "OFF")
  68.         sleep(1)
  69.         computer.shutdown(false)
  70.       end
  71.     sleep(1)
  72.     end
  73.   end)
  74.  
  75.   function setBundledOutput(color, state)
  76.     m.broadcast(123, color, state, sides.back)
  77.  
  78.   end
  79.  
  80.   local loop2 = thread.create(function()
  81.     while true do
  82.         time3 = os.date("*t")
  83.         cycledtime = time3.hour .. ":" .. time3.min
  84.        
  85.         -- traffic light code here (this will be what is ran during its normal cycle)
  86.  
  87.  
  88.     end
  89.  
  90.   end)
  91.   thread.waitForAny({loop1, loop2})
Advertisement
Add Comment
Please, Sign In to add comment