Adding Project 1 rotary encoder implementations
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#ifndef DIGITAL_IN_H
|
||||
#define DIGITAL_IN_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class Digital_in
|
||||
{
|
||||
public:
|
||||
Digital_in(int pin);
|
||||
|
||||
void init();
|
||||
|
||||
bool is_hi();
|
||||
bool is_lo();
|
||||
|
||||
private:
|
||||
uint8_t pinMask;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef DIGITAL_OUT_H
|
||||
#define DIGITAL_OUT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class Digital_out
|
||||
{
|
||||
public:
|
||||
Digital_out(int pin);
|
||||
|
||||
void init();
|
||||
void set_hi();
|
||||
void set_lo();
|
||||
void toggle();
|
||||
|
||||
private:
|
||||
uint8_t pinMask;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef ENCODER_H
|
||||
#define ENCODER_H
|
||||
|
||||
#include <digital_in.h>
|
||||
#include <digital_out.h>
|
||||
|
||||
class Encoder
|
||||
{
|
||||
public:
|
||||
Encoder(int c1Pin, int c2Pin, int ledPin);
|
||||
|
||||
void init();
|
||||
void update();
|
||||
int position();
|
||||
|
||||
private:
|
||||
Digital_in c1;
|
||||
Digital_in c2;
|
||||
Digital_out led;
|
||||
|
||||
bool previousC1;
|
||||
volatile int count;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user