Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[===================
- Made by: Nemo Eriksson
- Pastebin: p7sMDXJM
- Description: Displays an notification on monitor when timer has run out
- ====================]]--
- -- Recommended monitor size: 3x2
- function setTimer(timeAmount, timeUnit)
- -- Gets monitor and does some config stuff
- local monitor = peripheral.find('monitor')
- monitor.setTextScale(5)
- monitor.setTextColor(colors.red)
- monitor.clear()
- -- Speaker stuff
- local speaker = peripheral.find('speaker')
- local timerSound = 'block.glass.break'
- -- Calculates [delay]
- local unitConversion = {
- ['sec'] = 1,
- ['min'] = 60,
- ['hour'] = 3600
- }
- local delay = timeAmount * unitConversion[timeUnit]
- -- Print that timer has started
- print('Timer started at:', os.date())
- print('Timer duration:', timeAmount, timeUnit)
- -- Delays
- for second = 1, delay, 1 do
- os.sleep(1)
- end
- -- More monitor config
- monitor.clear()
- monitor.setCursorPos(1,1)
- -- Timer has gone off
- monitor.write('! ! !')
- monitor.setCursorPos(1,2) -- Moves to next line to fill screen with !!!
- monitor.write('! ! !')
- print('Timer has gone off at', os.date())
- -- Play alarm sound forever until program is terminated
- while true do
- speaker.playSound(timerSound)
- end
- end
- -- Main
- local args = {...}
- setTimer(args[1], args[2])
Add Comment
Please, Sign In to add comment