© 2024 EasyEDA Some rights reserved ISO/IEC
1.Easy to use and quick to get started
2.The process supports design scales of 300 devices or 1000 pads
3.Supports simple circuit simulation
4.For students, teachers, creators
1.Brand new interactions and interfaces
2.Smooth support for design sizes of over 5,000 devices or 10,000 pads
3.More rigorous design constraints, more standardized processes
4.For enterprises, more professional users
STD 360 rotary encoder
Mode: Editors' pick
/*
360RotaryEncoder
Read a rotary encoder with interrupts
Encoder&Switch hooked up with common to +5V
Read the press action with digitalread
ENCODER_A_PIN to pin 2
ENCODER_A_PIN to pin 3
SWITCH_PIN to pin 4
#define ENCODER_A_PIN 2
#define ENCODER_B_PIN 3
#define SWITCH_PIN 4
long position;
void setup(){
//setup our pins
pinMode(ENCODER_A_PIN, INPUT);
pinMode(ENCODER_B_PIN, INPUT);
pinMode(SWITCH_PIN, INPUT);
attachInterrupt(0, read_quadrature, CHANGE);
//setup our serial
Serial.begin(9600);
}
void loop(){
if (digitalRead(SWITCH_PIN) == LOW){
delay(10);
if (digitalRead(SWITCH_PIN) == LOW){
Serial.println("Switch Pressed");
}
}
Serial.print("Position: ");
Serial.println(position, DEC);
delay(1000);
}
void read_quadrature(){
// found a low-to-high on channel A
if (digitalRead(ENCODER_A_PIN) == LOW){
// check channel B to see which way
if (digitalRead(ENCODER_B_PIN) == LOW)
position++;
}
// found a high-to-low on channel A
else{
// check channel B to see which way
if (digitalRead(ENCODER_B_PIN) == LOW)
position--;
}
}
[1]: /editor/20151215/567000acc07bb.JPG
[2]: /editor/20151215/566fffe583d0f.jpgID | Name | Designator | Footprint | Quantity |
---|---|---|---|---|
1 | M05 | JP1 | 1X05 | 1 |
2 | rotary encoder | SW1 | ENCODER_LED_3_KIT | 1 |
3 | M03 | JP2 | 1X03 | 1 |
Unfold
Loading...
Do you need to add this project to the album?