Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.find("monitor")
- mon.setTextScale(2)
- local mW, mH = mon.getSize()
- local args = {...}
- local mins = 0
- local seconds = 0
- if #args == 0 then
- printError("Syntax: timer [minutes] <seconds>")
- return
- elseif #args == 1 then
- seconds = tonumber(args[1])
- else
- mins = tonumber(args[1])
- seconds = tonumber(args[2])
- end
- if seconds > 59 then
- mins = mins + math.floor(seconds / 60)
- seconds = seconds % 60
- end
- seconds = seconds + 1
- local startEpoch = os.epoch("utc") / 1000
- local lastFire = -1
- while mins > 0 or seconds > 0 do
- local time = math.floor(os.epoch("utc") / 1000 - startEpoch)
- if time > lastFire then
- lastFire = time
- seconds = seconds - 1
- if seconds == -1 then
- seconds = 59
- mins = mins - 1
- end
- mon.clear()
- local str = mins .. ":" .. string.format("%1.2d", seconds)
- mon.setCursorPos((mW - #str) / 2, mH / 2)
- mon.write(str)
- end
- sleep(0.25)
- end
- mon.clear()
- local str = "Done!"
- mon.setCursorPos((mW - #str) / 2, mH / 2)
- mon.write(str)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement