File Encoder.cpp¶
File List > Encoder > Encoder.cpp
Go to the documentation of this file
Source Code¶
#include "daisy_seed.h"
using namespace daisy;
DaisySeed hw;
Encoder encoder;
int main(void)
{
hw.Init();
encoder.Init(seed::D20, seed::D16, seed::D19);
hw.StartLog(true);
hw.PrintLine("Turn or click the encoder to start");
int output_value = 0;
while(1)
{
encoder.Debounce();
/* This will return a -1 if the encoder was turned counter clockwise, or
* a 1 if the encoder was turned clockwise, or 0 if the encoder was not rotated.
*/
int increment = encoder.Increment();
if(increment > 0)
{
output_value += 1;
hw.PrintLine("Output Value:\t%d", output_value);
}
else if(increment < 0)
{
output_value -= 1;
hw.PrintLine("Output Value:\t%d", output_value);
}
if(encoder.RisingEdge())
{
output_value = 0;
hw.PrintLine("Output Value:\t%d", output_value);
}
}
}