Author Topic: Getkey function on the Nspire (C)  (Read 6360 times)

0 Members and 1 Guest are viewing this topic.

_player1537

  • Guest
Getkey function on the Nspire (C)
« on: July 31, 2010, 01:17:59 am »
Stupid question could be percieved as stupid... what do I use to do "GetKey"?
« Last Edit: July 31, 2010, 02:00:40 am by DJ Omnimaga »

Offline northern_snow

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 132
  • Rating: +17/-1
    • View Profile
Re: Getkey function on the Nspire (C)
« Reply #1 on: July 31, 2010, 01:21:58 am »
Err... what do you mean? You want to program on nSpire with OS1.1? Even OS1.1 doesn't support "disp" command!

_player1537

  • Guest
Re: Getkey function on the Nspire (C)
« Reply #2 on: July 31, 2010, 01:24:49 am »
sorry, I meant in C.  Figured it out btw, isKeyDown().

Edit:  I think this thread might become my Ndless Question/Help thread (moreso C).  If someone wants to move it, that's fine.

Should this code work?  It should darken the screen, wait for you to press ESC, and quit.
Code: [Select]
#include <os.h>
#include "utils.h"

asm(".string \"PRG\"\n");

int main(void)
{
    int A;
    int B;
    for (A=0;A>319;A++){
        for (B=0;B>240;B++){
            setPixel(A,B,0xF);
        }
    }
    while (!isKeyPressed(KEY_NSPIRE_ESC)){}

    return 0;
}
« Last Edit: July 31, 2010, 01:30:32 am by _player1537 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Getkey function on the Nspire (C)
« Reply #3 on: July 31, 2010, 02:02:38 am »
Split in different topic and moved to C sub-forum.

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Getkey function on the Nspire (C)
« Reply #4 on: July 31, 2010, 02:23:31 am »
You need to change the for loop conditions to A < 320 and B < 240. With that said, here are some tips:
(1) You probably want to examine the first post in the Routines sticky for useful routines. I recommend skeleton.zip if you don't have it already. It has an extended os.h and utils.h with more functions and keycodes. It's also smaller, which makes for cleaner uploads.
(2) C style dictates that your variables should be in lowercase, with constants in uppercase.
(3) while(!isKeyPressed(KEY_NSPIRE_ESC)); works (note no braces!)
(4) For sake of readability (at least in my opinion), it is a good idea to make your hex numbers have leading zeroes (so use 0x0F instead of 0xF).
Congratulations on having written your first Nspire program! Welcome to the wonderful world of Nspire programming :)

_player1537

  • Guest
Re: Getkey function on the Nspire (C)
« Reply #5 on: July 31, 2010, 08:36:13 am »
ah, thank you!
1) Yep, already have that installed, and that is what I'm using atm for this.
2) Oops, I recall someone telling me that before. Fixed
3) ah, I see
4) Got it, fixed too

I also figured out that the lower the number, the darker the screen.  I thought it was 0x0F that was black x.x  I was looking through your Ncaster code, and I saw that you made your own array for the screen with malloc, is that a good practice I should use, or just use the screen memory itself?

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Getkey function on the Nspire (C)
« Reply #6 on: July 31, 2010, 01:55:42 pm »
You should use screenbuffers when you have any animation. For still images, or just text, its fine not to.

To allocate one, use:
Code: [Select]
char* scrbuf = (char*) malloc(SCREEN_BYTES_SIZE);and put scrbuf in function arguments.

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Getkey function on the Nspire (C)
« Reply #7 on: July 31, 2010, 03:53:20 pm »
@_player1537: You are right, 0x00 is black, 0x0F is white. Sorry for not pointing that out in my previous post.