Implement speedometer and encoder
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
#include "wheelEncoder.h"
|
||||
|
||||
WheelEncoder::WheelEncoder() {
|
||||
|
||||
}
|
||||
|
||||
void WheelEncoder::initEncoder(uint8_t pinA, uint8_t pinB) {
|
||||
this->pinA = pinA;
|
||||
this->pinB = pinB;
|
||||
|
||||
pinMode(this->pinA, INPUT_PULLDOWN);
|
||||
pinMode(this->pinB, INPUT_PULLDOWN);
|
||||
|
||||
|
||||
}
|
||||
|
||||
int64_t WheelEncoder::getCount() {
|
||||
return this->count;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef WHEEL_ENCODER_H
|
||||
#define WHEEL_ENCODER_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <Arduino.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/pcnt.h>
|
||||
|
||||
class WheelEncoder {
|
||||
public:
|
||||
WheelEncoder();
|
||||
void initEncoder(uint8_t pinA, uint8_t pinB);
|
||||
int64_t getCount();
|
||||
|
||||
private:
|
||||
uint8_t pinA;
|
||||
uint8_t pinB;
|
||||
bool init = false;
|
||||
|
||||
volatile int64_t count = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // WHEEL_ENCODER_H
|
||||
Reference in New Issue
Block a user