Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon -- table : peripheral, monitor
- local width -- int : width of the monitor
- --- INIT ---
- local function loadAPIs()
- if not fs.exists("lib/datetime") then
- error("[lib/datetime] file not found.")
- end
- os.loadAPI("lib/datetime")
- datetime.init()
- end
- local function init()
- mon = peripheral.find("monitor")
- if mon == nil then
- error("Monitor peripheral not found.")
- end
- width,_ = mon.getSize()
- mon.clear()
- mon.setTextScale(2)
- end
- --- UTILS ---
- local function writeCenter(str, width, y, color)
- if color then
- mon.setTextColor(color)
- end
- local x = (width - string.len(str) + 1) / 2
- mon.setCursorPos(x, y)
- mon.write(str)
- end
- --- FUNCTIONS ---
- local function displayTime()
- local infos = datetime.getDatetime2()
- if infos then
- mon.clear()
- writeCenter(string.upper(infos["dayOfWeek"]), width, 1, colors.blue)
- writeCenter(infos["day"] .. "/" .. infos["month"] .. "/" .. infos["day"], width, 3, colors.blue)
- writeCenter(infos["hour"] .. ":" .. infos["min"], width, 5, colors.blue)
- if string.upper(infos["dayOfWeek"]) == "DIMANCHE" and tonumber(infos["hour"]) >= 20 then
- writeCenter("RESET", width, 2, colors.red)
- writeCenter("BIENTOT", width, 4, colors.red)
- end
- end
- end
- --- MAIN CALL ---
- local function main()
- loadAPIs()
- init()
- while true do
- displayTime()
- sleep(1)
- end
- end
- main()
Add Comment
Please, Sign In to add comment