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.cpp
00001 #include "mbed.h" 00002 #include "CRotaryEncoder.h" 00003 00004 CRotaryEncoder::CRotaryEncoder(PinName pinA, PinName pinB) 00005 { 00006 m_pinA = new InterruptIn(pinA); 00007 m_pinA->rise(this, &CRotaryEncoder::rise); 00008 m_pinA->fall(this, &CRotaryEncoder::fall); 00009 00010 m_pinB = new DigitalIn(pinB); 00011 m_position = 0; 00012 } 00013 00014 CRotaryEncoder::~CRotaryEncoder() 00015 { 00016 delete m_pinA; 00017 delete m_pinB; 00018 } 00019 00020 int CRotaryEncoder::Get(void) 00021 { 00022 return m_position; 00023 } 00024 00025 void CRotaryEncoder::Set(int value) 00026 { 00027 m_position = value; 00028 } 00029 00030 00031 void CRotaryEncoder::fall(void) 00032 { 00033 if(*m_pinB == 1) 00034 { 00035 m_position++; 00036 } 00037 else 00038 { 00039 m_position--; 00040 } 00041 } 00042 00043 void CRotaryEncoder::rise(void) 00044 { 00045 if(*m_pinB == 1) 00046 { 00047 m_position--; 00048 } 00049 else 00050 { 00051 m_position++; 00052 } 00053 } 00054
Generated on Thu Jul 28 2022 08:09:47 by
1.7.2