add SW encoder callback support and example

This commit is contained in:
hathach committed 2017-09-14 23:54:08 +07:00
1 parent 5d03ea59d0
commit 3db9b9150a
3 files changed
+24 -9

No files matched your search

@@ -28,20 +28,21 @@ void setup()
// Initialize Encoder
swEncoder.begin(PIN_A, PIN_B);
swEncoder.setCallback(encoder_callback);
}
void loop()
{
int value = swEncoder.read();
// do nothing
}
if (value)
void encoder_callback(int step)
{
if ( step > 0 )
{
if ( value > 0 )
{
Serial.println("Right");
}else
{
Serial.println("Left");
}
Serial.println("Right");
}else
{
Serial.println("Left");
}
}