Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of scoreLight_Advanced by
hardwareIO/CRotaryEncoder.h
- Committer:
- mbedalvaro
- Date:
- 2014-12-02
- Revision:
- 48:7633d8e7b0d3
- Parent:
- 42:c4e9c1116af4
File content as of revision 48:7633d8e7b0d3:
#ifndef CROTENC_H_INCLUDED
#define CROTENC_H_INCLUDED
#include "mbed.h"
/* This Class handles a rotary encoder like the one from Pollin electronic (Panasonic EVEP...).
* It uses two pins, one creating an interrupt on change.
* Rotation direction is determined by checking the state of the other pin.
*
* Operating the encoder changes an internal integer value that can be read
* by Get() or the operator int() functions.
* A new value can be set by Set(value) or opperator=.
*
* Autor: Thomas Raab (Raabinator)
*
* Dent steady point ! ! !
* +-----+ +-----+
* pinA (interrupt) | | | |
* --+ +-----+ +---
* +-----+ +-----+
* pinB | | | |
* ----+ +-----+ +-
* --> C.W
* CW: increases position value
* CCW: decreases position value
*
* changelog:
*
* 09. Nov. 2010
* First version published.
*
*/
#define ROTARY_ENCODER1_PINA p21
#define ROTARY_ENCODER1_PINB p22
#define ROTARY_ENCODER2_PINA p26
#define ROTARY_ENCODER2_PINB p27
class CRotaryEncoder
{
public:
CRotaryEncoder(PinName pinA, PinName pinB);
~CRotaryEncoder();
int Get(void);
inline operator int() { return Get(); }
void Set(int value);
inline CRotaryEncoder& operator= ( int value ) { Set(value); return *this; }
void SetMinMax(int min, int max);
bool CheckNew();
private:
void wrapValue();
InterruptIn *m_pinA;
DigitalIn *m_pinB;
volatile int m_position, maxValue, minValue;
volatile bool newValue;
void rise(void);
void fall(void);
};
extern CRotaryEncoder rotaryEncoder1;
extern CRotaryEncoder rotaryEncoder2;
#endif
