sWaffle7982

timer

Aug 6th, 2021 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. --[[===================
  2.  
  3. Made by: Nemo Eriksson
  4. Pastebin: p7sMDXJM
  5. Description: Displays an notification on monitor when timer has run out
  6.  
  7. ====================]]--
  8.  
  9. -- Recommended monitor size: 3x2
  10.  
  11. function setTimer(timeAmount, timeUnit)
  12.   -- Gets monitor and does some config stuff
  13.   local monitor = peripheral.find('monitor')
  14.   monitor.setTextScale(5)
  15.   monitor.setTextColor(colors.red)
  16.   monitor.clear()
  17.  
  18.   -- Speaker stuff
  19.   local speaker = peripheral.find('speaker')
  20.   local timerSound = 'block.glass.break'
  21.  
  22.   -- Calculates [delay]
  23.   local unitConversion = {
  24.     ['sec'] = 1,
  25.     ['min'] = 60,
  26.     ['hour'] = 3600
  27.   }
  28.   local delay = timeAmount * unitConversion[timeUnit]
  29.  
  30.   -- Print that timer has started
  31.   print('Timer started at:', os.date())
  32.   print('Timer duration:', timeAmount, timeUnit)
  33.  
  34.   -- Delays
  35.   for second = 1, delay, 1 do
  36.     os.sleep(1)
  37.   end
  38.  
  39.   -- More monitor config
  40.   monitor.clear()
  41.   monitor.setCursorPos(1,1)
  42.  
  43.   -- Timer has gone off
  44.   monitor.write('! ! !')
  45.   monitor.setCursorPos(1,2)    -- Moves to next line to fill screen with !!!
  46.   monitor.write('! ! !')
  47.   print('Timer has gone off at', os.date())
  48.  
  49.   -- Play alarm sound forever until program is terminated
  50.   while true do
  51.     speaker.playSound(timerSound)
  52.   end
  53. end
  54.  
  55. -- Main
  56. local args = {...}
  57. setTimer(args[1], args[2])
  58.  
Add Comment
Please, Sign In to add comment