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.
encoder.h
00001 // 00002 // Encoder Class 00003 // 00004 // 2019.10.13 ... Originally written by Y.Kuroda 00005 // 00006 #ifndef _COUNTER_H 00007 #define _COUNTER_H 00008 00009 class Encoder { 00010 public: 00011 Encoder(PinName pin) : _interrupt(pin), _count(0) { // create the InterruptIn on the pin specified to Counter 00012 _interrupt.rise(callback(this, &Encoder::increment)); // attach increment function of this counter instance 00013 _interrupt.fall(callback(this, &Encoder::increment)); // attach increment function of this counter instance 00014 } 00015 00016 void increment() { _count++; } 00017 int read() const { return _count; } 00018 int set(int c) { return _count=c; } 00019 int reset(){ return set(0); } 00020 00021 int operator=(int c) { return set(c); } 00022 // Encoder& operator=(Encoder& c){ return *this; } 00023 // int operator=(Encoder& c){ return read(); } 00024 00025 operator int() const { return read(); } 00026 00027 protected: 00028 InterruptIn _interrupt; 00029 volatile int _count; 00030 }; 00031 00032 #endif 00033
Generated on Tue Jul 26 2022 06:00:34 by
1.7.2