update encoder
This commit is contained in:
1 parent
f13e3f6113
commit
97ecc06347
3 files changed
+24
-6
No files matched your search
@@ -44,7 +44,7 @@
|
||||
void RotaryEncoder::begin(void)
|
||||
{
|
||||
// default sample period
|
||||
NRF_QDEC->SAMPLEPER = QDEC_SAMPLEPER_SAMPLEPER_16384us;
|
||||
NRF_QDEC->SAMPLEPER = QDEC_SAMPLEPER_SAMPLEPER_128us;
|
||||
|
||||
pinMode(_pina, INPUT);
|
||||
pinMode(_pinb, INPUT);
|
||||
@@ -130,6 +130,24 @@ int32_t RotaryEncoder::read(void)
|
||||
return NRF_QDEC->ACCREAD;
|
||||
}
|
||||
|
||||
int32_t RotaryEncoder::readAbs(void)
|
||||
{
|
||||
// first update the abs
|
||||
read();
|
||||
|
||||
return _abs;
|
||||
}
|
||||
|
||||
void RotaryEncoder::writeAbs(int32_t value)
|
||||
{
|
||||
_abs = value;
|
||||
}
|
||||
|
||||
void RotaryEncoder::clearAbs(void)
|
||||
{
|
||||
_abs = 0;
|
||||
}
|
||||
|
||||
void QDEC_IRQHandler(void)
|
||||
{
|
||||
|
||||
|
||||
@@ -60,6 +60,9 @@ class RotaryEncoder
|
||||
void stop(void);
|
||||
|
||||
int32_t read(void);
|
||||
int32_t readAbs(void);
|
||||
void writeAbs(int32_t value);
|
||||
void clearAbs(void);
|
||||
|
||||
private:
|
||||
uint8_t _pina, _pinb;
|
||||
|
||||
@@ -26,9 +26,6 @@ void setup()
|
||||
// Initialize Encoder
|
||||
encoder.begin();
|
||||
|
||||
// Enable hardware debouncing
|
||||
encoder.setDebounce(false);
|
||||
|
||||
// Start encoder
|
||||
encoder.start();
|
||||
}
|
||||
@@ -41,10 +38,10 @@ void loop()
|
||||
{
|
||||
if ( value > 0 )
|
||||
{
|
||||
Serial.println("Right");
|
||||
Serial.println("Left");
|
||||
}else
|
||||
{
|
||||
Serial.println("Left");
|
||||
Serial.println("Right");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user