I have created yet another library, this one will allow the user to select a number on the NXT screen using the NXT buttons. Uses the CenterText library to center the displayed text.
/*
ChooseNum.Lib.nxc
*/
#include "CenterText.Lib.nxc"
int ChooseNum(string label, int y, int min, int max) {
int value = (max+min)/2;
while(!ButtonPressed(BTNCENTER,0)) {
string msg = StrCat(label,NumToStr(value));
TextOut(CenterText(msg), y, msg);
if(ButtonPressed(BTNRIGHT,0)) {
while(ButtonPressed(BTNRIGHT,0));
value++;
}
if(ButtonPressed(BTNLEFT,0)) {
while(ButtonPressed(BTNLEFT,0));
value--;
}
if (value < min) value = max;
if (value > max) value = min;
}
while(ButtonPressed(BTNCENTER,0));
return value;
}
Thank you for the code and for cluing me in on this functionality of NXC. I'm New to NXC and Mindstorms and learning fast. I modified you code to fit my needs and though I would share with you. I allow the user to hold the key down for scrolling through long list of numbers and also let me preset the start point. Next I might add a function to speed up the scroll if I hold the button for 10 counts.