Answers for "arduino button next array"

1

arduino button next array

int arrayName[10]={1,2,3,4,5,6,7,8,9,0}	//your array
int arrayPosition=0;					//the position of your array. Dont let it get bigger than the array

void loop(){
    serial.println(arrayPosition);		
    if(buttonPressed){		//debounce this
	    arrayPosition++		//incrament this value when the button is pressed
	    if(arrayPosition==11){	//reset it if it gets bigger than the array
		    arrayPosition=0;
	    }
    }
}
Posted by: Guest on May-02-2021

Browse Popular Code Answers by Language