[LIB] ChooseNum
Posted: 01 Aug 2012, 03:42
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.
Use:
Code:
Download:
Use:
Code: Select all
#include "ChooseNum.Lib.nxc"
int myvalue = ChooseNum( "Value: ", LCD_LINE3, 0, 9 );
Code: Select all
/*
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;
}