1#ifndef BYTE_SIZED_ENCODER_DECODER_H
2#define BYTE_SIZED_ENCODER_DECODER_H
65 wire->endTransmission();
76 ByteSizedEncoderDecoder(TwoWire* _wire, uint8_t _address = 14, int16_t _encoderSlowestInterval = 0, int16_t _encoderEnoughCounts = 0)
104 for (
byte i = 0; i < 8; i++) {
122 for (
byte i = 0; i < 8; i++) {
138 if (n > 8 || n < 1) {
152 void begin(
boolean resetEncoders =
true)
167 wire->endTransmission(
true);
168 delayMicroseconds(50);
169 for (
byte i = 0; i < 8; i++) {
176 if (
wire->available())
179 if (
wire->available())
181 if (high == -1 || low == -1) {
185 encoderCount[i] = (((uint16_t)high) << 8 | ((uint16_t)low));
190 unsigned long mic = micros();
191 int32_t hundredMicrosSinceLastRead = (mic -
lastReadMicros[i]) / 100;
212 if (n > 8 || n < 1) {
229 if (n > 8 || n < 1) {
245 if (n > 8 || n < 1) {
257 if (resetVariables) {
258 for (
byte i = 0; i < 8; i++) {
285 if (n > 8 || n < 1) {
class for communicating with the firmware on a Byte Sized Encoder Decoder board
Definition byte-sized-encoder-decoder.h:8
void resetEncoderPositions(boolean resetVariables=true)
resets all encoder positions to 0
Definition byte-sized-encoder-decoder.h:254
int16_t encoderVelocity[8]
array of 8 numbers representing the velocity of each encoder (steps per second)
Definition byte-sized-encoder-decoder.h:45
int16_t lastVelocityEncoderCount[8]
array of 8 numbers representing the last encoder count read from the board for velocity calculation
Definition byte-sized-encoder-decoder.h:29
boolean isEncoderActive(uint8_t n)
whether you have set to read data from a specific encoder
Definition byte-sized-encoder-decoder.h:283
int16_t getEncoderPositionWithoutOverflows(uint8_t n, boolean read=false)
gets the position of an encoder as the 16 bit number that the board returns (it loops around and over...
Definition byte-sized-encoder-decoder.h:224
int16_t encoderEnoughCounts[8]
enough counts to calculate velocity from
Definition byte-sized-encoder-decoder.h:53
void run()
reads the encoder positions from the board
Definition byte-sized-encoder-decoder.h:163
uint8_t whichEncodersMask
bit mask of which encoders to read from
Definition byte-sized-encoder-decoder.h:37
uint8_t address
I2C address of the Byte Sized Encoder Decoder board (as selected by the jumpers)
Definition byte-sized-encoder-decoder.h:13
boolean isVelNewVal[8]
array of 8 booleans representing whether the velocity was just calculated
Definition byte-sized-encoder-decoder.h:57
void setEncoderEnoughCounts(uint8_t n, int16_t counts)
set the value of encoderEnoughCounts
Definition byte-sized-encoder-decoder.h:116
int16_t getEncoderVelocity(uint8_t n, boolean read=false)
gets the velocity of an encoder
Definition byte-sized-encoder-decoder.h:240
int16_t encoderCount[8]
array of 8 numbers representing the number of steps each encoder has taken
Definition byte-sized-encoder-decoder.h:17
TwoWire * wire
I2C bus to communicate over.
Definition byte-sized-encoder-decoder.h:33
int32_t getEncoderPosition(uint8_t n, boolean read=false)
gets the position of an encoder as a 32 bit signed integer (it counts how many times the 16 bit numbe...
Definition byte-sized-encoder-decoder.h:207
int16_t encoderSlowestInterval[8]
after this many milliseconds without an encoder tick velocity is set to zero.
Definition byte-sized-encoder-decoder.h:49
int16_t encoderOverflows[8]
array of 8 numbers representing the number of times each encoder's counter variable has overflowed
Definition byte-sized-encoder-decoder.h:21
void setWhichEncoders(uint8_t mask)
set which encoders you want to receive data from
Definition byte-sized-encoder-decoder.h:271
boolean isVelNew(uint8_t n)
whether the velocity was just calculated
Definition byte-sized-encoder-decoder.h:136
void write(uint8_t data)
helper function to write a byte to the board
Definition byte-sized-encoder-decoder.h:61
void setEncoderSlowestInterval(uint8_t n, int16_t interval)
set the value of encoderSlowestInterval
Definition byte-sized-encoder-decoder.h:98
unsigned long lastReadMicros[8]
the last time the encoders were read (microseconds)
Definition byte-sized-encoder-decoder.h:41
int16_t lastEncoderCount[8]
array of 8 numbers representing the last encoder count read from the board
Definition byte-sized-encoder-decoder.h:25
ByteSizedEncoderDecoder(TwoWire *_wire, uint8_t _address=14, int16_t _encoderSlowestInterval=0, int16_t _encoderEnoughCounts=0)
Constructor for the Byte Sized Encoder Decoder class.
Definition byte-sized-encoder-decoder.h:76
void begin(boolean resetEncoders=true)
sets up the Byte Sized Encoder Decoder board all it really does is tell the board to read from all en...
Definition byte-sized-encoder-decoder.h:152