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.
Dependents: encoder_test distance_measure speed_measure straight_speed_control ... more
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 00036 00037 class CRotaryEncoder 00038 { 00039 public: 00040 CRotaryEncoder(PinName pinA, PinName pinB); 00041 ~CRotaryEncoder(); 00042 00043 int Get(void); 00044 inline operator int() { return Get(); } 00045 00046 void Set(int value); 00047 inline CRotaryEncoder& operator= ( int value ) { Set(value); return *this; } 00048 00049 private: 00050 InterruptIn *m_pinA; 00051 DigitalIn *m_pinB; 00052 volatile int m_position; 00053 00054 void rise(void); 00055 void fall(void); 00056 00057 00058 }; 00059 00060 00061 #endif
Generated on Thu Jul 28 2022 08:09:47 by
1.7.2