Using the NXT buttons with NXC
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Using the NXT buttons with NXC
How do you use the NXT buttons with NXC? I know all this was discussed on nxtasy, but I forget how to do it, so I am asking here. Ideally, I would like an example program that includes the functions, including the whole "back" button thing (locking/delaying for exiting programs that way). Thanks.
Edit: I just realized the starter can edit the topic name! (unlike nxtasy).
Edit2: you can also delete posts without needing to request it be done.
Edit: I just realized the starter can edit the topic name! (unlike nxtasy).
Edit2: you can also delete posts without needing to request it be done.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Using the NXT buttons with NXC
What may help you more is reading the NXC Guide and Help section on the button module and experimenting with the available functions to see what they do. Using the back button requires the enhanced NBC/NXC firmware, of course. With it on your brick you can call SetLongAbort(true). You can also totally disable the abort operation by setting the abort flag to be something that can never happen (look for SetAbortFlag in the help). If you do that then pulling a battery or using a direct command remotely will be the only way to stop your program. Or your program could have an exit condition within its user interface that lets you stop the program.
http://bricxcc.sourceforge.net/nbc/nxcd ... tions.html
From the NXC help:
Normally you want to check for a button click or "bump" which involves waiting for a press and then waiting for a not press (aka release). You may want to write a function that encapsulates this in a way you prefer which you can then reuse in all your programs that require button press handling.
John Hansen
http://bricxcc.sourceforge.net/nbc/nxcd ... tions.html
From the NXC help:
Code: Select all
task main()
{
#ifdef __ENHANCED_FIRMWARE
SetLongAbort(true);
#endif
while(true)
{
#ifdef __ENHANCED_FIRMWARE
NumOut(0, LCD_LINE1, ButtonPressed(BTNEXIT, false));
#endif
NumOut(0, LCD_LINE2, ButtonPressed(BTNRIGHT, false));
NumOut(0, LCD_LINE3, ButtonPressed(BTNLEFT, false));
NumOut(0, LCD_LINE4, ButtonPressed(BTNCENTER, false));
}
}
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Using the NXT buttons with NXC
Exactly what I was looking for, thanks.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Using the NXT buttons with NXC
Somehow I think he missed the suggestion about reading the guide.
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Using the NXT buttons with NXC
Me? I did go and read it for a while, and I found it helpful, however, example programs ALWAYS are (for me) a better way to learn what can be done with a function (and more importantly, HOW to use it) than just reading what the guide has to say about it. Just in the program he provided, John answered all the questions I had at the time (in regard to the situation).dhystad wrote:Somehow I think he missed the suggestion about reading the guide.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
-
- Posts: 73
- Joined: 29 Sep 2010, 12:05
Re: Using the NXT buttons with NXC
I strongly urge you to purchase a copy of John Hansen's book LEGO MINDSTORMS NXT, POWER PROGRAMMING IN C, (2nd edition). It is full of the kind of examples you are looking for and can be bought for less than US$20 from Amazon.mattallen37 wrote:Me? I did go and read it for a while, and I found it helpful, however, example programs ALWAYS are (for me) a better way to learn what can be done with a function (and more importantly, HOW to use it) than just reading what the guide has to say about it. Just in the program he provided, John answered all the questions I had at the time (in regard to the situation).dhystad wrote:Somehow I think he missed the suggestion about reading the guide.
Regards, Morton
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Using the NXT buttons with NXC
Is there a digital version (PDF) of the book?
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
-
- Posts: 73
- Joined: 29 Sep 2010, 12:05
Re: Using the NXT buttons with NXC
Not that I am aware of. It would be useful if there were. I'd buy a PDF copy if I could.mattallen37 wrote:Is there a digital version (PDF) of the book?
Regards, Morton
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Using the NXT buttons with NXC
I already have two paperback Mindstorms books, and any time I want to program based on an example, I have to type it all in, which can take a LONG time. It would be really nice to have them all in PDF.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Using the NXT buttons with NXC
Did you know that you CAN make a virus for the NXT? I just made one, and it took me 10+ minutes to restore it, even with the reset button and all that.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Who is online
Users browsing this forum: No registered users and 0 guests