Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: lkj on October 21, 2011, 02:17:05 pm

Title: Timers in the Nspire
Post by: lkj on October 21, 2011, 02:17:05 pm
Can anybody explain me how  to use the timers of the nspire, pls? I haven't ever used timers before and don't understand the explanations on hackspire.
Title: Re: Timers in the Nspire
Post by: Jim Bauwens on October 22, 2011, 01:29:27 pm
Its quite easy:
Spoiler For Lua:
Code: (Lua) [Select]
msg = "tick"
function on.create ()
   timer.start(1) --start the timer, make it tick every second
end
function on.paint(gc)
    gc:drawString(msg, 10, 10, "top")
end

function on.timer()
    if msg == "tick" then
        msg = "tack"
    else
        msg = "tick"
    end
    platform.invalidate()
end

Sorry, I thought this was a lua question :D
Title: Re: Timers in the Nspire
Post by: lkj on October 22, 2011, 03:13:26 pm
No, I can't code in lua :)
Title: Re: Timers in the Nspire
Post by: Adriweb on October 22, 2011, 03:15:11 pm
(although it's easier than C/native)

;)
Title: Re: Timers in the Nspire
Post by: Chockosta on November 01, 2011, 08:35:37 am
Well, a while ago, I started a project which was supposed to be a 84+ like clock for the nspire. (With Ndless)
But Lua came, so I gave up.

Here is the code used to display the time :
Code: [Select]
    bufDrawString(buf, 50, 0, "Nspire clock - By Loic Pujet", 0);
    uint32_t time = *(volatile uint32_t*) 0x90090000;
    sprintf(clock, "%lu : %lu : %lu", (time%86400)/3600, (time%3600)/60, time%60);
    bufDrawString(buf, 115, 150, clock, 0);

EDIT : Oops, I haven't seen that this post was quite old.
But maybe it will be useful for someone
Title: Re: Timers in the Nspire
Post by: lkj on November 02, 2011, 02:26:26 pm
I know how to use the Real Time Clock, but I don't know about the timer at address 0x900D0000 (http://hackspire.unsads.com/wiki/index.php/Memory-mapped_I/O_ports#900D0000_-_Second_timer).
Title: Re: Timers in the Nspire
Post by: Chockosta on November 02, 2011, 02:30:08 pm
Oh, sorry.

Well I only use this timer as a random seed...
So I don't know how it works.
Title: Re: Timers in the Nspire
Post by: lkj on December 15, 2011, 05:23:24 pm
I figured out how it works by now, but I have a problem with my program doing nothing for some seconds. I think this is caused by the ndless function wait_no_key_pressed(). Should this function work normally if I change the timer divider and some other things with the timer? Or does it also use the timers and my changes make it work strange?
Title: Re: Timers in the Nspire
Post by: calc84maniac on December 16, 2011, 10:26:19 am
I figured out how it works by now, but I have a problem with my program doing nothing for some seconds. I think this is caused by the ndless function wait_no_key_pressed(). Should this function work normally if I change the timer divider and some other things with the timer? Or does it also use the timers and my changes make it work strange?
wait_no_key_pressed() does use the timer because it calls the idle() function to save power. The equivalent without power saving is while(any_key_pressed());
Title: Re: Timers in the Nspire
Post by: lkj on December 17, 2011, 05:31:41 pm
Thank you, now it works.