// these are functions for handling the buttons. // these functions should have to change very much // to work in the hardware version, // unlike the functions in the "faux_buttons" tab. int narrowDownButtonsInit(){ int start = 0; int end = on.length; boolean stillLooking = true; int found = -1; while(stillLooking){ if(end-start <= 1){ stillLooking = false; found = start; } else{ int[] new_range = narrowDownButtonsIter(start, end); start = new_range[0]; end = new_range[1]; } } return found; } int[] narrowDownButtonsIter(int start, int end){ int middle = start + (end-start)/2; int[] newRange = {start, start}; // a range of zero will mean nothing was found if(faux_isAButtonOnInRange(start, middle)){ newRange[0] = start; newRange[1] = middle; } if(faux_isAButtonOnInRange(middle, end)){ newRange[0] = middle; newRange[1] = end; } return newRange; }