Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
hardware:arduino [2015/03/04 17:53]
admin [Rotary encoders]
hardware:arduino [2015/03/04 17:57]
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 {
 
hardware/arduino.txt · Last modified: 2015/03/04 18:07 by admin