Helly everyone,
I am using a RAMPS 1.4 Shield to power and control my stepper motor. Now I want to add a push button to pause and resume the stepper motor. Therefore, I connected D1 and GND (see image) with a simple switch in between and then used the code below. However, no matter if I press the button or not, the LED will not change. It is always on. The button worked fine on another bord, so I guess either I have to change the code or the pin connection on the board. Do you have any suggestions to solve my problem?
void setup() {
//start serial connection
Serial.begin(9600);
//configure pin 1 as an input and enable the internal pull-up resistor
pinMode(1, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
//read the pushbutton value into a variable
int sensorVal = digitalRead(1);
//print out the value of the pushbutton
Serial.println(sensorVal);
// Keep in mind the pull-up means the pushbutton's logic is inverted. It goes
// HIGH when it's open, and LOW when it's pressed. Turn on pin LED_BUILTIN when the
// button's pressed, and off when it's not:
if (sensorVal == HIGH) {
digitalWrite(LED_BUILTIN, LOW);
} else {
digitalWrite(LED_BUILTIN, HIGH);
}
}