Try something like this:
void loop() {
buttonState1 = digitalRead(buttonPin1); // read the state of the pushbutton value:
buttonState2 = digitalRead(buttonPin2); // read the state of the pushbutton value:
if (buttonState1 == HIGH) { // check if the button is pressed
myStepper.step(300); // Step forward 300 steps:
Serial.println("Switch Up");
} else if (buttonState2 == HIGH) { // check if the button is pressed
myStepper.step(-300); // Step backward 100 steps:
Serial.println("Switch Down");
}
if (Serial.available()) {
nextChar = Serial.read(); // read just one character
if (nextChar == up) {// check for 'u'
myStepper.step(300); // Step forward 300 steps:
Serial.println("Serial Up");
} else if (nextChar == down) { // check for 'd'
myStepper.step(-300); // Step backward 100 steps:
Serial.println("Serial Down");
}
}
}
But again, I think you're going to have trouble with your switches. If you push it, it will be connected to 5V and read HIGH. If you don't push it....what is it connected to? Nothing? Then it will be floating and may continue to read HIGH all the time. If this is your scheme then at least connect a 10k resistor from the digital input to ground to keep it from floating when the switch is not pushed.
--
The
Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons