Description
Encoder characteristics:
• Operating voltage 3-15V
• Number of pulses per revolution - 20
• Dimensions 2x3x3 cm
Wiring diagram:
Sketch example:
int pinA = 3Wiring diagram: // output number, подключенный к CLK енкодера int pinB = 4Wiring diagram: // controller pin number, подключенный к DT енкодера int encoderPosCount = 0; int pinALast; int aVal; boolean bCW; void setup() { pinMode (pinA,INPUT); pinMode (pinB,INPUT); /* Read the value on pin A and store it as the last value on that pin */ pinALast = digitalRead(pinA); Serial.begin (9600); } void loop() { aVal = digitalRead(pinA); if (aVal != pinALast){ // checking for a change in the value at pin A compared to the previous stored one, which means, that the shaft has turned // and to determine the direction of rotation, we need output B. if (digitalRead(pinB) != aVal) { // If pin A changed first - вращение по часовой стрелке encoderPosCount ++; bCW = true; } else {// иначе B изменил свое состояние первым - вращение против часовой стрелки bCW = false; encoderPosCount--; } Serial.print ("Вращение: "); if (bCW){ Serial.println ("по часовой стрелке"); }else{ Serial.println("против часовой стрелки"); } Serial.print("Положение енкодера: "); Serial.println(encoderPosCount); } pinALast = aVal; }
чтение карты if ( ! mfrc522.PICC_ReadCardSerial()) return;
Reviews
There are no reviews yet.