
21Chapter 1: The Foundation of Robotic Arms
STEP 2
int btn;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
}
void loop() {
btn = digitalRead(2);
Serial.println(btn);
delay(100);
}
STEP 3
We will compile and upload our code just as we did before. Once the code
has been uploaded, open the Serial Monitor. While the push-button is not
being pressed, you should see the number 1 printing over and over again.
When the push-button is pressed, that number should change to a 0. 1s and
0s—sound familiar? It’s binary! Remember, 1 is the same as on or high, and
0 is the same as off or low. Now that we know our push-button works, let’s
take things one step ...