
156 Make: Robotic Arms
int motorSelector = 1;
int btnVal;
void setup() {
Serial.begin(9600);
pinMode(13, INPUT_PULLUP);
}
void loop() {
btnVal = digitalRead(13);
if(btnVal == LOW){
motorSelector++;
delay(250);
}
if(motorSelector == 6){
motorSelector = 1;
}
Serial.print("Active Motor: ");
Serial.println(motorSelector);
}
Here, our first variable is our motor-selection variable, and we give it an
initial value of 1 because we’d like to default to controlling motor 1 whenever
the program begins. Next, we have a variable to store and keep track of the
info coming from our button.
Inside the void setup, all we need to do is start the Serial Monitor to make
sure our ...