Schrittmotor mit 2 Tastern steuern - gleiches Verhalten trotz unterschiedlicher Befehle:
Ziel:
Schrittmotor soll bei Taster1 10x drehen vorwärts , beim Taster 2. soll er 2x drehen rückwärts.
Das ganze entprellt, dass der Motor immer an der selbenstelle stehen bleibt.
Problem:
Kein Hexenwerk - dachte ich auch - aber der Schrittmotor zeigt bei beiden Tasten das gleiche Drehverhalten, und er dreht nicht immer wieder zu richtigen Position zurück. Wenn ich das ganze via serial monitor initiere funktioniert es.
Also irgenwas ist bei mir systematisch falsch.
Ich bin für jede Hilfe offen.
Fritzing, Foto, Sketch findet ihr im Anhang. - vielleicht geht meine Verkabellung auch einfach nicht.
Schon mal Danke für eure Hilfe
/*
Button
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* Note: on most Arduinos there is already an LED on the board
attached to pin 13.
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 8; // the number of the pushbutton pin
const int buttonPin2 = 9; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = LOW; // variable for reading the pushbutton status
int buttonread = 0;
int buttonState2 = LOW; // variable for reading the pushbutton status
int buttonread2 = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
Serial.begin(9600);
}
void loop() {
//--------------------- Button 1 ------------------------
buttonread = digitalRead(buttonPin);
if (buttonread == HIGH) {
delay(5);
if (digitalRead(buttonPin)) { //Check button twice
if (buttonState == LOW)
{
if (digitalRead(buttonPin)) {
// turn LED on:
// digitalWrite(ledPin, HIGH);
buttonState = HIGH;
Serial.println("Button pressed");
}
}
}
}
else {
if (buttonState == HIGH) {
//digitalWrite(ledPin, LOW);
buttonState = LOW;
}
}
//-------------------
//--------------------- Button 2 ------------------------
buttonread2 = digitalRead(buttonPin2);
if (buttonread2 == HIGH) {
delay(5);
if (digitalRead(buttonPin2)) { //Check button twice
if (buttonState2 == LOW)
{
if (digitalRead(buttonPin2)) {
// turn LED on:
// digitalWrite(ledPin, HIGH);
buttonState2 = HIGH;
Serial.println("Button 2 pressed");
}
}
}
}
else {
if (buttonState2 == HIGH) {
//digitalWrite(ledPin, LOW);
buttonState2 = LOW;
}
}
}
entprellter2taster_V00-4_E-APP.ino (2.2 KB)