task main () { int keys = 0; unsigned byte key[] = {0}; int number = 0; string output; nxtDisplayCenteredTextLine(0, "Mindsensors"); nxtDisplayCenteredBigTextLine(1, "NumPad"); nxtDisplayCenteredTextLine(3, "Test 1"); nxtDisplayCenteredTextLine(5, "Connect sensor"); nxtDisplayCenteredTextLine(6, "to S1"); wait1Msec(2000); eraseDisplay(); nxtDisplayCenteredTextLine(0, "Mindsensors NP"); nxtDisplayTextLine(1, "-------------------"); nxtDisplayTextLine(5, "-------------------"); nxtDisplayTextLine(7, "X: no key"); while (true) { // Which key is being pressed now? if (!MSNPscanKeys(MSNP, keys, key[0], number)) StopAllTasks(); // "convert" to string so we can print it output = key; nxtDisplayTextLine(3, "Numpad Key: %s", output); nxtDisplayTextLine(4, "Numpad Num: %d", number); wait1Msec(100); } }
//function to get passenger's current y location from numeric keypad int get_passenger_location_y(){ int keys = 0; unsigned byte key[] = {0}; int number = 0; string output; eraseDisplay(); displayCenteredTextLine(0, "Enter y-location"); displayTextLine(1, "-------------------"); displayTextLine(5, "-------------------"); while (true){ if (!MSNPscanKeys(MSNP, keys, key[0], number)) stopAllTasks(); if ((number>=0)&&(number<20)){ //if (number == 8){number = 0;} displayTextLine(3, "Numpad Key: %d", number); wait1Msec(1000); sleep(100); return number; break; } } }