• DISCONTINUED

Rotary Encoder - Illuminated (Red/Green)

:CEL06005
€3.45
Tax included

Rotary encoders are used similarly to potentiometers. They’re different from potentiometers in that an encoder has full rotation without limits. They output gray code so that you can tell how much and in which direction the encoder has been turned.

  • Built in LED RED/GREEN

If you have any questions on this product please feel free to contact us.

*Disclaimer: The images are merely illustrative.

DESCRIÇÃO EM PORTUGUÊS BREVEMENTE DISPONÍVEL

Se tiver alguma dúvida neste produto não hesite em contactar-nos.

*Atenção: as imagens são meramente ilustrativas.

DESCRIPTION

Rotary encoders are used similarly to potentiometers. They’re different from potentiometers in that an encoder has full rotation without limits. They output gray code so that you can tell how much and in which direction the encoder has been turned.

This encoder is especially cool because it has a red/green LED built in, as well as a push-button. Look below for the clear knob that goes with this potentiometer.

FEATURES

  • Switch Travel: 0.5mm
  • Shaft Diameter: 6.0mm
  • Shaft Length: 18mm
  • Vertical Through-Hole Mount
  • Red/Green LED
  • Pushbutton

DOCUMENTS

ARDUINO SAMPLE CODE:

//From bildr article: http://bildr.org/2012/08/rotary-encoder-arduino/
//these pins can not be changed 2/3 are special pins
int encoderPin1 = 2;
int encoderPin2 = 3;
volatile int lastEncoded = 0;
volatile long encoderValue = 0;
long lastencoderValue = 0;
int lastMSB = 0;
int lastLSB = 0;

void setup() {
    Serial.begin(9600);

    pinMode(encoderPin1, INPUT);
    pinMode(encoderPin2, INPUT);

    digitalWrite(encoderPin1, HIGH); //turn pullup resistor on
    digitalWrite(encoderPin2, HIGH); //turn pullup resistor on

    //call updateEncoder() when any high/low changed seen
    //on interrupt 0 (pin 2), or interrupt 1 (pin 3)
    attachInterrupt(0, updateEncoder, CHANGE);
    attachInterrupt(1, updateEncoder, CHANGE);
}

void loop() {
    //Do stuff here
    Serial.println(encoderValue);
    delay(1000); //just here to slow down the output, and show it will work even during a delay
}

void updateEncoder() {
    int MSB = digitalRead(encoderPin1); //MSB = most significant bit
    int LSB = digitalRead(encoderPin2); //LSB = least significant bit
    int encoded = (MSB << 1) | LSB;
    //converting the 2 pin value to single number int sum = (lastEncoded << 2) | encoded; 
    //adding it to the previous encoded value if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) encoderValue ++; if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) encoderValue --; lastEncoded = encoded; 
    //store this value for next time 
}

CEL06005

You might also like