Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CRotaryEncoder.h Source File

CRotaryEncoder.h

00001 #ifndef CROTENC_H_INCLUDED
00002 #define CROTENC_H_INCLUDED
00003 
00004 #include "mbed.h"
00005 
00006 
00007 /* This Class handles a rotary encoder like the one from Pollin electronic (Panasonic EVEP...).
00008  * It uses two pins, one creating an interrupt on change.
00009  * Rotation direction is determined by checking the state of the other pin.
00010  *
00011  * Operating the encoder changes an internal integer value that can be read
00012  * by Get() or the operator int() functions.
00013  * A new value can be set by Set(value) or opperator=.
00014  *
00015  * Autor: Thomas Raab (Raabinator)
00016  *
00017  * Dent steady point     !     !     !
00018  *                    +-----+     +-----+
00019  * pinA (interrupt)   |     |     |     |
00020  *                  --+     +-----+     +---
00021  *                      +-----+     +-----+
00022  * pinB                 |     |     |     |
00023  *                  ----+     +-----+     +-
00024  *                           --> C.W
00025  * CW:  increases position value
00026  * CCW: decreases position value
00027  *
00028  * changelog:
00029  *
00030  * 09. Nov. 2010
00031  *     First version published.
00032  *
00033  */
00034 
00035 #define ROTARY_ENCODER1_PINA p21
00036 #define ROTARY_ENCODER1_PINB p22
00037 
00038 #define ROTARY_ENCODER2_PINA p26
00039 #define ROTARY_ENCODER2_PINB p27
00040 
00041 class CRotaryEncoder
00042 {
00043     public:
00044     CRotaryEncoder(PinName pinA, PinName pinB);
00045     ~CRotaryEncoder();
00046     
00047     int Get(void);
00048     inline operator int() { return Get(); }
00049 
00050     void Set(int value);
00051     inline CRotaryEncoder& operator= ( int  value ) { Set(value); return *this; }
00052     
00053     void SetMinMax(int min, int max);
00054     
00055     bool CheckNew();
00056 
00057     private:
00058     void wrapValue();
00059     InterruptIn     *m_pinA;
00060     DigitalIn       *m_pinB;
00061     volatile int    m_position, maxValue, minValue;
00062     volatile bool newValue;
00063     
00064     void rise(void);
00065     void fall(void);
00066     
00067 
00068 };
00069 
00070 extern CRotaryEncoder rotaryEncoder1;
00071 extern CRotaryEncoder rotaryEncoder2;
00072 
00073 #endif