Virgilcore

countdown clock

Feb 1st, 2022 (edited)
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. local timerLength = 120 --Time in seconds
  2. local monitorLocation = "top" --The monitor location, it can be monitor_XXX or the side the monitor is on
  3. local redstoneSide = "right" --What side of the computer the redstone is on
  4. local redstoneSide2 = "left" --What side of the computer the redstone is on
  5. local monitor = peripheral.wrap(monitorLocation) -- I get a handle for the monitor
  6. function SecondsToClock(seconds)
  7.   local seconds = tonumber(seconds)
  8.  
  9.   if seconds <= 0 then
  10.     monitor.write("00:00");
  11.   else
  12.     mins = string.format("%u", math.floor(seconds/60));
  13.     secs = string.format("%u", math.floor(seconds - mins *60));
  14.     monitor.write(mins)
  15.     monitor.write(":")
  16.     monitor.write(secs)
  17.   end
  18. end
  19. function ResetCountDown(number)
  20.     sleep(number)
  21.     monitor.clear()
  22.     rs.setOutput(redstoneSide, false)
  23.     rs.setOutput(redstoneSide2, false)
  24.     os.reboot()
  25. end
  26. monitor.setTextColor(colors.orange)
  27. monitor.setTextScale(4)
  28. rs.setOutput(redstoneSide, false)
  29. rs.setOutput(redstoneSide2, false) --put the redstone on
  30. for i=timerLength, 0, -1 do -- we start the countdown loop
  31.    monitor.setCursorPos(2, 1)
  32.    monitor.clear()-- clear the monitor
  33.    SecondsToClock(i)
  34.    sleep(1) -- let a second pass
  35.    if i == 20 then --check if we have reached 20
  36.     monitor.clear()
  37.     monitor.setCursorPos(1, 1)
  38.     monitor.write("Ignition")
  39.     rs.setOutput(redstoneSide, true) -- make it on
  40.     rs.setOutput(redstoneSide2, true)
  41.     sleep(1)
  42.    end --close the if
  43. monitor.clear()
  44. monitor.setCursorPos(1, 1)
  45. monitor.write("Liftoff")
  46. end --we close the loop
  47. sleep(timerLength)
  48. ResetCountDown(10)
Add Comment
Please, Sign In to add comment