Hallo zusammen,
ich bin relativ neu in der Arduino Welt und bastel gerade an folgender Steuerung:
Rotary Encoder regelt den rechts/linkslauf eines Nema 17 Schnrittmotors. Soweit kein Problem.
Ich habe das nach dem Video umgesetzt: How Rotary Encoder Works and How To Use It with Arduino - YouTube
Ich würde gerne zusätzlich den Wertebereich durch Tastendrücke ändern.
Ich möchte dadurch die Drehungsgeschwindigkeit beschleunigen.
In etwa so:
- im Normalfall dreht sich der Stepper langsam wie im Ursprungscode und eine LED leuchtet.
- einmal den Taster drücken - > der Stepper dreht sich Faktor 5 (ca.) mal so schnell und 2 LEDs leuchtten
- Doppeldruck (schnell hintereinander) auf den Taster -> der Stepper dreht sich Faktor 10 (ca.) mal so schnell und 3 LEDs leuchten
- Trippeldruck (schnell hintereinander) auf den Taster -> der Stepper dreht sich wieder normal und eine LED leuchtet.
mein verwendeter Encoder (Keyes KY-040) hat diese Tastenfunktion eingebaut. Das System läuft auf einem UNO
Das ist der Code und das funktioniert wie beschrieben, leider bekomme ich das mit den Tasten nicht eingebunden.
Kann mir da jemand evtl. helfen? Code oder Fingerzeige auf Code reicht - Verkabelung ist klar
1000 Dank und Gruß Micha
/* Arduino Rotary Encoder Tutorial
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
*/
#define outputA 6
#define outputB 7
int counter = 0;
int aState;
int aLastState;
void setup() {
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
Serial.begin (9600);
// Reads the initial state of the outputA
aLastState = digitalRead(outputA);
}
void loop() {
aState = digitalRead(outputA); // Reads the "current" state of the outputA
// If the previous and the current state of the outputA are different, that means a Pulse has occured
if (aState != aLastState){
// If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
if (digitalRead(outputB) != aState) {
counter ++;
} else {
counter --;
}
Serial.print("Position: ");
Serial.println(counter);
}
aLastState = aState; // Updates the previous state of the outputA with the current state
}