14 posts
Posted 05 June 2012 - 05:40 PM
Hi, i started my OS and I want to show the time on a monitor.
This is the code for the loop:
function time()
while true do
term.setCursorPos(30,3)
-- code to show time program on top monitor
sleep (1)
end
end
I will turn on time() when the computer starts.
I made it to auto refresh by loop.
I need the code for the rest.
Thanks for help!
1604 posts
Posted 05 June 2012 - 06:17 PM
If you want to run the time program, you can use shell.run("time") after redirecting the output to the monitor (with term.redirect(<monitor>)). But for something so simple as showing the time, it's better to do it yourself in the same program.
Example:
-- get the monitor
local mon = peripherals.wrap("<side>")
if not mon then
print("No monitor found")
end
-- print the time
mon.clear()
mon.setCursorPos(1, 1)
mon.write(textutils.formatTime(os.time()))
It writes the time to the monitor on the specified time. You can put the monitor initialization at the start, and then put the rest on the loop.
1054 posts
Posted 05 June 2012 - 06:29 PM
And if you're interested in a multithreaded one (time on the monitor and using your pc for other stuff as well), here is a simple adaptation:
function time()
return textutils.formatTime(os.time(), true)
end
local side = 'top'
local mon = peripheral.wrap(side)
local ok, err = pcall( function()
parallel.waitForAny(
function()
while true do
mon.clear()
mon.setCursorPos(2,3)
mon.write(time())
sleep(1)
end
end,
function()
os.run( {}, "rom/programs/shell" )
end
)
end )
14 posts
Posted 06 June 2012 - 04:37 AM
there is an option to do this and work on the computer at the same time?
14 posts
Posted 07 June 2012 - 11:41 AM
help please?
2447 posts
Posted 07 June 2012 - 12:11 PM
Did you not read the post right above yours which gave you code to do exactly that?
14 posts
Posted 07 June 2012 - 03:12 PM
ya… sorry but thanks!