save loops

Dependencies:   mbed

Committer:
mbedalvaro
Date:
Tue Dec 02 08:29:59 2014 +0000
Revision:
1:3be7b7d050f4
Parent:
0:df6fdd9b99f0
updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:df6fdd9b99f0 1 #ifndef CROTENC_H_INCLUDED
mbedalvaro 0:df6fdd9b99f0 2 #define CROTENC_H_INCLUDED
mbedalvaro 0:df6fdd9b99f0 3
mbedalvaro 0:df6fdd9b99f0 4 #include "mbed.h"
mbedalvaro 0:df6fdd9b99f0 5
mbedalvaro 0:df6fdd9b99f0 6
mbedalvaro 0:df6fdd9b99f0 7 /* This Class handles a rotary encoder like the one from Pollin electronic (Panasonic EVEP...).
mbedalvaro 0:df6fdd9b99f0 8 * It uses two pins, one creating an interrupt on change.
mbedalvaro 0:df6fdd9b99f0 9 * Rotation direction is determined by checking the state of the other pin.
mbedalvaro 0:df6fdd9b99f0 10 *
mbedalvaro 0:df6fdd9b99f0 11 * Operating the encoder changes an internal integer value that can be read
mbedalvaro 0:df6fdd9b99f0 12 * by Get() or the operator int() functions.
mbedalvaro 0:df6fdd9b99f0 13 * A new value can be set by Set(value) or opperator=.
mbedalvaro 0:df6fdd9b99f0 14 *
mbedalvaro 0:df6fdd9b99f0 15 * Autor: Thomas Raab (Raabinator)
mbedalvaro 0:df6fdd9b99f0 16 *
mbedalvaro 0:df6fdd9b99f0 17 * Dent steady point ! ! !
mbedalvaro 0:df6fdd9b99f0 18 * +-----+ +-----+
mbedalvaro 0:df6fdd9b99f0 19 * pinA (interrupt) | | | |
mbedalvaro 0:df6fdd9b99f0 20 * --+ +-----+ +---
mbedalvaro 0:df6fdd9b99f0 21 * +-----+ +-----+
mbedalvaro 0:df6fdd9b99f0 22 * pinB | | | |
mbedalvaro 0:df6fdd9b99f0 23 * ----+ +-----+ +-
mbedalvaro 0:df6fdd9b99f0 24 * --> C.W
mbedalvaro 0:df6fdd9b99f0 25 * CW: increases position value
mbedalvaro 0:df6fdd9b99f0 26 * CCW: decreases position value
mbedalvaro 0:df6fdd9b99f0 27 *
mbedalvaro 0:df6fdd9b99f0 28 * changelog:
mbedalvaro 0:df6fdd9b99f0 29 *
mbedalvaro 0:df6fdd9b99f0 30 * 09. Nov. 2010
mbedalvaro 0:df6fdd9b99f0 31 * First version published.
mbedalvaro 0:df6fdd9b99f0 32 *
mbedalvaro 0:df6fdd9b99f0 33 */
mbedalvaro 0:df6fdd9b99f0 34
mbedalvaro 0:df6fdd9b99f0 35 #define ROTARY_ENCODER1_PINA p21
mbedalvaro 0:df6fdd9b99f0 36 #define ROTARY_ENCODER1_PINB p22
mbedalvaro 0:df6fdd9b99f0 37
mbedalvaro 0:df6fdd9b99f0 38 #define ROTARY_ENCODER2_PINA p26
mbedalvaro 0:df6fdd9b99f0 39 #define ROTARY_ENCODER2_PINB p27
mbedalvaro 0:df6fdd9b99f0 40
mbedalvaro 0:df6fdd9b99f0 41 class CRotaryEncoder
mbedalvaro 0:df6fdd9b99f0 42 {
mbedalvaro 0:df6fdd9b99f0 43 public:
mbedalvaro 0:df6fdd9b99f0 44 CRotaryEncoder(PinName pinA, PinName pinB);
mbedalvaro 0:df6fdd9b99f0 45 ~CRotaryEncoder();
mbedalvaro 0:df6fdd9b99f0 46
mbedalvaro 0:df6fdd9b99f0 47 int Get(void);
mbedalvaro 0:df6fdd9b99f0 48 inline operator int() { return Get(); }
mbedalvaro 0:df6fdd9b99f0 49
mbedalvaro 0:df6fdd9b99f0 50 void Set(int value);
mbedalvaro 0:df6fdd9b99f0 51 inline CRotaryEncoder& operator= ( int value ) { Set(value); return *this; }
mbedalvaro 0:df6fdd9b99f0 52
mbedalvaro 0:df6fdd9b99f0 53 void SetMinMax(int min, int max);
mbedalvaro 0:df6fdd9b99f0 54
mbedalvaro 0:df6fdd9b99f0 55 bool CheckNew();
mbedalvaro 0:df6fdd9b99f0 56
mbedalvaro 0:df6fdd9b99f0 57 private:
mbedalvaro 0:df6fdd9b99f0 58 void wrapValue();
mbedalvaro 0:df6fdd9b99f0 59 InterruptIn *m_pinA;
mbedalvaro 0:df6fdd9b99f0 60 DigitalIn *m_pinB;
mbedalvaro 0:df6fdd9b99f0 61 volatile int m_position, maxValue, minValue;
mbedalvaro 0:df6fdd9b99f0 62 volatile bool newValue;
mbedalvaro 0:df6fdd9b99f0 63
mbedalvaro 0:df6fdd9b99f0 64 void rise(void);
mbedalvaro 0:df6fdd9b99f0 65 void fall(void);
mbedalvaro 0:df6fdd9b99f0 66
mbedalvaro 0:df6fdd9b99f0 67
mbedalvaro 0:df6fdd9b99f0 68 };
mbedalvaro 0:df6fdd9b99f0 69
mbedalvaro 0:df6fdd9b99f0 70 extern CRotaryEncoder rotaryEncoder1;
mbedalvaro 0:df6fdd9b99f0 71 extern CRotaryEncoder rotaryEncoder2;
mbedalvaro 0:df6fdd9b99f0 72
mbedalvaro 0:df6fdd9b99f0 73 #endif