GamearooCodes

Ramp Meters TC card only

May 2nd, 2023 (edited)
1,243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.91 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. local sides = require("sides")
  7. local colors = require("colors")
  8. local thread = require("thread")
  9. -- cords
  10.  
  11.  
  12.  
  13. function sleep(n)
  14.     os.sleep(n)
  15.   end
  16.   local rampOn = "False"
  17.   local lastState = "off"
  18. console = "East Left"
  19.   time = os.date("*t")
  20.   cycledtime = time.hour .. ":" .. time.min
  21.  
  22.   function start()
  23.     redlight.setState(-1336, 64, -582, "Green", true, false) --3
  24.     redlight.setState(-1328, 68, -585, "Green", true, false)-- 4
  25.     sleep(3)
  26.     redlight.setState(-1336, 64, -582, "Green", false, false) --6
  27.     redlight.setState(-1328, 68, -585, "Green", false, false) -- 4
  28.     redlight.setState(-1336, 64, -582, "Yellow", true, false) -- 3
  29.     redlight.setState(-1328, 68, -585, "Yellow", true, false) -- 4
  30.     sleep(2)
  31.     redlight.setState(-1336, 64, -582, "Yellow", false, false) --3
  32.     redlight.setState(-1328, 68, -585, "Yellow", false, false) --4
  33.     redlight.setState(-1336, 64, -582, "Red", true, false) --3
  34.     redlight.setState(-1328, 68, -585, "Red", true, false) --4
  35.     redlight.setState(-1336, 65, -582, "Red", true, false) --5
  36.     sleep(1)
  37.     lastState = "on"
  38. end
  39.  
  40. local loop1 = thread.create(function()
  41.     while true  do
  42.    
  43.       time2 = os.date("*t")
  44.      
  45.       term.clear()
  46.       print("Time Cycled: " .. cycledtime)
  47.       print("Current Time: " .. time2.hour .. ":" .. time2.min)
  48.     print("Ramps Are " .. lastState);
  49.     if(time2.hour == 6) or (time2.hour == 7) or (time2.hour == 8) or (time2.hour == 18) or (time2.hour == 19) or (time2.hour == 20)  then
  50.         print("2")
  51.         if (rampOn == "False") then
  52.             print("3")
  53.         rampOn = "True"
  54.         redlight.setState(-1388, 70, -586, "Yellow", true, true) -- 1
  55.         redlight.setState(-1387, 70, -585, "Yellow", true, true) -- 2
  56.         start()
  57.         end
  58.     else
  59.         print("4")
  60.         if(rampOn == "True") then
  61.             print("66")
  62.             print("ok")
  63.             rampOn = "False"
  64.             redlight.setState(-1387, 70, -585, "Yellow", false, true) -- 1
  65.             redlight.setState(-1387, 70, -585, "Yellow", false, true) -- 2
  66.         end
  67.         print("5")
  68.     end
  69.     sleep(1)
  70.     end
  71.   end)
  72.  
  73.  
  74.  
  75.   function checkTime(time)
  76.     print("1")
  77.    
  78. print("end")
  79.    
  80. end
  81.  
  82.     function running()
  83.         print("1")
  84.        
  85.     end
  86.    
  87.  
  88.  
  89.  
  90.   local loop2 = thread.create(function()
  91.     while true do
  92.         time3 = os.date("*t")
  93.         cycledtime = time3.hour .. ":" .. time3.min
  94.         if(rampOn == "True") and (lastState == "on") then
  95.             print("2")
  96.             redlight.setState(-1336, 64, -582, "Red", false, false) --3
  97.             redlight.setState(-1328, 68, -585, "Red", false, false) --4
  98.             redlight.setState(-1336, 65, -582, "Red", false, false) --5
  99.             redlight.setState(-1336, 64, -582, "Green", true, false) --3
  100.             redlight.setState(-1328, 68, -585, "Green", true, false) --4
  101.             sleep(0.5)
  102.            
  103.             redlight.setState(-1336, 64, -582, "Green", false, false) --3
  104.             redlight.setState(-1328, 68, -585, "Green", false, false) --4
  105.             redlight.setState(-1336, 64, -582, "Red", true, false) --3
  106.             redlight.setState(-1328, 68, -585, "Red", true, false) --4
  107.             redlight.setState(-1336, 65, -582, "Red", true, false) --5
  108.             sleep(3)
  109.         else
  110.            if(rampOn == "False") and (lastState == "on") then
  111.          redlight.clearStates(-1336, 64, -582) --3
  112.          redlight.clearStates(-1328, 68, -585) --4
  113.          redlight.clearStates(-1336, 65, -582) --5
  114.          redlight.clearStates(-1336, 65, -582) --1
  115.          redlight.clearStates(-1336, 65, -582) --2
  116.          lastState = "off"
  117.            end
  118.          sleep(1)
  119.         end
  120.         sleep(1)
  121.  
  122.     end
  123.  
  124.   end)
  125.   thread.waitForAny({loop1, loop2})
Advertisement
Add Comment
Please, Sign In to add comment