Ich möchte einen Steppermotor mit 2 Tasten steuern. Eine taste für vor und die andere für zurück.
Ich habe versucht mit previous1 und preveous2 zu arbeiten aber bekomme das nicht hin.
Hier meine bisherige Version wo Taster 2 als Umschalter der Richtung fungiert.
#define Direction 13 //Direction Pin - Initial State is ZERO
#define Step 12 //Step Pin - Pulse this to step the motor in the direction selected by the Direction Pin
#define StepsPerRev 600 //How many steps our motor needs to do a full rotation
int inPin1 = 8; // the number of the input pin (for pull-down)
int inPin2 = 5; // the number of the input pin (for pull-up)
int DirectionToggle = 0; //Just a Toggle for the Direction Flag
byte incomingByte;
int previous1 = LOW; // the previous reading from the input pin 1
int previous2 = HIGH; // the previous reading from the input pin 2
int reading;
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup()
{
pinMode(Direction, OUTPUT);
pinMode(Step, OUTPUT);
pinMode(inPin1, INPUT);
pinMode(inPin2, INPUT);
}
void loop()
{
reading = digitalRead(inPin1);
digitalWrite(Direction,DirectionToggle);
if (reading == HIGH) {
digitalWrite(Step,HIGH);
delay(1);
digitalWrite(Step,LOW);
delay(1);
time = millis();
}
previous1 = reading;
reading = digitalRead(inPin2);
if (reading == LOW && previous2 == HIGH && millis() - time > debounce) {
DirectionToggle=!DirectionToggle;
time = millis();
}
previous2 = reading;
}
Kann mir jemand erklären wie ich es hinbekomme das ein Taster vorwärts dreht und der andere Rückwärts solange ich den Taster gedrückt halte ?
Danke