Details

Rotary encoder module
Item No.: 86Duino-KY040
Price: USD 2.50 (Approximately)
 NTD 81.25 (Exact Amount)
Stock: In Stock
Features:

Rotary encoder module

Share Product:
Quantity:
Total:USD (Approximately)
        (NTD )(Exact Amount)
Add to Cart

Product Information

Rotary encoder can be counted by rotating forward and reverse direction during rotation of the output pulse frequency,

 

Specifications

  • Size:32x28x19mm(approx)

 

Sample code

int brightness = 120;    // how bright the LED is, start at half brightness

int fadeAmount = 10;    // how many points to fade the LED by

unsigned long currentTime;

unsigned long loopTime;

const int pin_A = 10;  // pin 12

const int pin_B = 11;  // pin 11

unsigned char encoder_A;

unsigned char encoder_B;

unsigned char encoder_A_prev=0;

 

void setup()  {

  pinMode(pin_A, INPUT);

  pinMode(pin_B, INPUT);

  currentTime = millis();

  loopTime = currentTime;

 Serial.begin(9600);

}

 

void loop()  {

  // get the current elapsed time

  currentTime = millis();

  if(currentTime >= (loopTime + 5)){

    // 5ms since last check of encoder = 200Hz 

    encoder_A = digitalRead(pin_A);    // Read encoder pins

    encoder_B = digitalRead(pin_B);  

    if((!encoder_A) && (encoder_A_prev)){

      // A has gone from high to low

      if(encoder_B) {

        // B is high so clockwise

        // increase the brightness, dont go over 255

        if(brightness + fadeAmount <= 255) brightness += fadeAmount;              

      }  

      else {

        // B is low so counter-clockwise     

        // decrease the brightness, dont go below 0

        if(brightness - fadeAmount >= 0) brightness -= fadeAmount;              

      }  

 

    }  

    encoder_A_prev = encoder_A;     // Store value of A for next time   

   

    loopTime = currentTime;  // Updates loopTime

   

    Serial.println(brightness);

  }

  // Other processing can be done here

                          

}

 

What's Included

  • Rotary encoder module x 1pcs

 

Applications

 

Download

 

 

The product has been added to cart!

The product has been added to cart!
Your shopping cart has0items. Total amount: USD0.00(NTD 0.00)