- [Show page]
- [Old revisions]
- [[unknown link type]]
- []
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
hardware:arduino [2015/03/04 17:53] admin [Rotary encoders] |
hardware:arduino [2015/03/04 18:07] (current) admin [Rotary encoders] |
||
---|---|---|---|
Line 19: | Line 19: | ||
* direct attach to two (2) interrupt pins, keyword: passive waiting | * direct attach to two (2) interrupt pins, keyword: passive waiting | ||
* using external IO with counter, keyword: any time baby, any time :) | * using external IO with counter, keyword: any time baby, any time :) | ||
+ | |||
+ | Huge note: dont forget 10k pull up resistors. | ||
ad 1) | ad 1) | ||
Line 58: | Line 60: | ||
ad 2) Using interrupts to read a rotary encoder is a perfect job for interrupts because the interrupt service routine (a function) can be short and quick, because it doesn't need to do much. | ad 2) Using interrupts to read a rotary encoder is a perfect job for interrupts because the interrupt service routine (a function) can be short and quick, because it doesn't need to do much. | ||
- | |||
- | **HUGE NOTE: pull up resistors** | ||
<code> | <code> | ||
- | #define encoder0PinA 2 | + | #define encoderPinA 2 |
- | #define encoder0PinB 4 | + | #define encoderPinB 4 |
- | volatile unsigned int encoder0Pos = 0; | + | volatile int encoderPos = 0; |
void setup() { | void setup() { | ||
Line 72: | Line 72: | ||
MyInterrupt() { | MyInterrupt() { | ||
- | if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) { | + | if (digitalRead(encoderPinA) == digitalRead(encoderPinB)) { |
encoderPos++; | encoderPos++; | ||
} else { | } else { | ||
Line 80: | Line 80: | ||
</code> | </code> | ||
- | You can print the value outside the MyIntterupt() routine, which should be as fast&small as possible. | + | You can print the value **outside** not inside the MyIntterupt() routine, which should be as fast&small as possible. |
<code> | <code> | ||
void loop() { | void loop() { |
hardware/arduino.1425487995.txt.gz · Last modified: 2015/03/04 17:53 by admin