driver for incremental encoder

Committer:
ianaherne
Date:
Thu Mar 28 16:28:55 2019 +0000
Revision:
6:2fdce74d2a7b
Parent:
5:1a5772466668
added function to change limits

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ianaherne 0:c3a05fe15b84 1 #ifndef DECODER_H
ianaherne 0:c3a05fe15b84 2 #define DECODER_H
ianaherne 0:c3a05fe15b84 3 #include "mbed.h"
ianaherne 5:1a5772466668 4 extern Serial pc;
ianaherne 0:c3a05fe15b84 5
ianaherne 0:c3a05fe15b84 6
ianaherne 0:c3a05fe15b84 7
ianaherne 0:c3a05fe15b84 8 class decoder{
ianaherne 0:c3a05fe15b84 9
ianaherne 0:c3a05fe15b84 10 public:
ianaherne 0:c3a05fe15b84 11
ianaherne 6:2fdce74d2a7b 12
ianaherne 2:b82d31306c4b 13
ianaherne 0:c3a05fe15b84 14 decoder(PinName channelA,PinName channelB);
ianaherne 0:c3a05fe15b84 15
ianaherne 0:c3a05fe15b84 16 void isr();
ianaherne 0:c3a05fe15b84 17
ianaherne 0:c3a05fe15b84 18 int8_t getDirection();
ianaherne 0:c3a05fe15b84 19 int16_t getCount();
ianaherne 6:2fdce74d2a7b 20 void setLimits(int8_t lower, int8_t upper);
ianaherne 1:017efde7ab29 21 void reset();
ianaherne 0:c3a05fe15b84 22
ianaherne 0:c3a05fe15b84 23
ianaherne 0:c3a05fe15b84 24
ianaherne 0:c3a05fe15b84 25 private:
ianaherne 0:c3a05fe15b84 26
ianaherne 1:017efde7ab29 27 InterruptIn _channelA; // interrupt only required on one channel
ianaherne 1:017efde7ab29 28 DigitalIn _channelB; // channelB is only required for comparison to determine direction
ianaherne 0:c3a05fe15b84 29
ianaherne 0:c3a05fe15b84 30
ianaherne 0:c3a05fe15b84 31 int8_t _direction;
ianaherne 0:c3a05fe15b84 32 int16_t _count;
ianaherne 6:2fdce74d2a7b 33 int8_t _lowerLimit;
ianaherne 6:2fdce74d2a7b 34 int8_t _upperLimit;
ianaherne 6:2fdce74d2a7b 35
ianaherne 4:9913990cfd78 36
ianaherne 0:c3a05fe15b84 37
ianaherne 0:c3a05fe15b84 38
ianaherne 0:c3a05fe15b84 39 };
ianaherne 0:c3a05fe15b84 40
ianaherne 0:c3a05fe15b84 41 #endif