Author Topic: Timers in the Nspire  (Read 5769 times)

0 Members and 1 Guest are viewing this topic.

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Timers in the Nspire
« 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.

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Timers in the Nspire
« Reply #1 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
« Last Edit: October 22, 2011, 01:32:25 pm by jimbauwens »

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: Timers in the Nspire
« Reply #2 on: October 22, 2011, 03:13:26 pm »
No, I can't code in lua :)

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Timers in the Nspire
« Reply #3 on: October 22, 2011, 03:15:11 pm »
(although it's easier than C/native)

;)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: Timers in the Nspire
« Reply #4 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
« Last Edit: November 01, 2011, 08:38:03 am by Chockosta »

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: Timers in the Nspire
« Reply #5 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.

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: Timers in the Nspire
« Reply #6 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.

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: Timers in the Nspire
« Reply #7 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?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Timers in the Nspire
« Reply #8 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());
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: Timers in the Nspire
« Reply #9 on: December 17, 2011, 05:31:41 pm »
Thank you, now it works.