I'm learning how to use an encoder.
I am using the code below from a Teensy tutorial I found.
However, when I run it, nothing displays in the serial window.
I'm using the Ardunio IDE with the Teensy option installed. I can run a simple serial Hello World sketch so that seems to work ok. And I can run the fast blink sketch and the LED on my Teensy 3.2 board blinks accordingly.
So for my encoder code below, something must be wrong or I have the wrong setup on my breadboard.
Thanks for any help.
I am using the code below from a Teensy tutorial I found.
However, when I run it, nothing displays in the serial window.
I'm using the Ardunio IDE with the Teensy option installed. I can run a simple serial Hello World sketch so that seems to work ok. And I can run the fast blink sketch and the LED on my Teensy 3.2 board blinks accordingly.
So for my encoder code below, something must be wrong or I have the wrong setup on my breadboard.
Thanks for any help.
Code:
/* Encoder Library - TwoKnobs Example
* http://www.pjrc.com/teensy/td_libs_Encoder.html
*
* This example code is in the public domain.
*/
#include <Encoder.h>
// Change these pin numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder knobRight(5, 6);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
Serial.println("Knob Encoder Test:");
}
long positionRight = -999;
void loop() {
long newRight;
newRight = knobRight.read();
if (newRight != positionRight)
{
Serial.print(", Right = ");
Serial.print(newRight);
Serial.println();
positionRight = newRight;
}
// if a character is sent from the serial monitor,
// reset knob back to zero.
if (Serial.available())
{
Serial.read();
Serial.println("Reset knob to zero");
knobRight.write(0);
}
}