Fork of mRotaryEncoder for mdeb-os. uses newer version of PinDetect. Testprogram: https://os.mbed.com/users/charly/code/mRotaryEncoder_HelloWorld-os/
Dependents: mRotaryEncoder_HelloWorld-os TMC2209-Test2
mRotaryEncoder Class Reference
This Class handles a rotary encoder with mechanical switches and an integrated pushbutton It uses two pins, one creating an interrupt on change. More...
#include <mRotaryEncoder.h>
Public Member Functions | |
| mRotaryEncoder (PinName pinA, PinName pinB, PinName pinSW, PinMode pullMode=PullUp, int debounceTime_us=1000, int detectRise=1, int detectFall=1) | |
| Create a mechanical rotary encoder object connected to the specified pins. | |
| ~mRotaryEncoder () | |
| destroy object | |
| int | Get (void) |
| Get the actual value of the rotary position. | |
| void | Set (int value) |
| Set the current position value. | |
| void | attachSW (Callback< void()> cb) |
| attach a function to be called when switch is pressed | |
| void | attachROT (Callback< void()> cb) |
| attach an object member function to be called when switch is pressed | |
| void | attachROTCW (Callback< void()> cb) |
| attach an object member function to be called when shaft is rotated | |
| void | attachROTCCW (Callback< void()> cb) |
| attach an object member function to be called when shaft is rotated clockwise | |
Protected Attributes | |
| Callback< void()> | rotIsr |
| Callback system. | |
| Callback< void()> | rotCWIsr |
| clockwise rotated | |
| Callback< void()> | rotCCWIsr |
| counterclockwise rotated | |
Detailed Description
This Class handles a rotary encoder with mechanical switches and an integrated pushbutton It uses two pins, one creating an interrupt on change.
Rotation direction is determined by checking the state of the other pin. Additionally a pushbutton switch is detected
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) Extended by Karl Zweimueller (charly)
Dent steady point ! ! ! +-----+ +-----+ pinA (interrupt) | | | | --+ +-----+ +--- +-----+ +-----+ pinB | | | | ----+ +-----+ +- --> C.W CW: increases position value CCW: decreases position value
changelog:
09. Nov. 2010 First version published Thomas Raab raabinator 26.11.2010 extended by charly - pushbutton, pullmode, debounce, callback-system Feb2011 Changes InterruptIn to PinDetect which does the debounce of mechanical switches Mar2020 Configurable detection of rise/fall events to account for different types of encoders (half as much dent points)
Definition at line 40 of file mRotaryEncoder.h.
Constructor & Destructor Documentation
| mRotaryEncoder | ( | PinName | pinA, |
| PinName | pinB, | ||
| PinName | pinSW, | ||
| PinMode | pullMode = PullUp, |
||
| int | debounceTime_us = 1000, |
||
| int | detectRise = 1, |
||
| int | detectFall = 1 |
||
| ) |
Create a mechanical rotary encoder object connected to the specified pins.
- Parameters:
-
pinA Switch A of quadrature encoder pinB Switch B of quadrature encoder pinSW Pin for push-button switch pullmode mode for pinA pinB and pinSW like DigitalIn.mode debounceTime_us time in micro-seconds to wait for bouncing of mechanical switches to end detectRise Detect rise event as new rotation. default 1 detectFall Detect fall event as new rotation. default 1
Definition at line 5 of file mRotaryEncoder.cpp.
| ~mRotaryEncoder | ( | ) |
destroy object
Definition at line 36 of file mRotaryEncoder.cpp.
Member Function Documentation
| void attachROT | ( | Callback< void()> | cb ) |
attach an object member function to be called when switch is pressed
- Parameters:
-
tptr pointer to object mprt pointer ro member function callback-System for rotation of shaft
attach a function to be called when the shaft is rotated keep this function short, as no interrrupts can occour within
- Parameters:
-
cb callback-function
Definition at line 109 of file mRotaryEncoder.h.
| void attachROTCCW | ( | Callback< void()> | cb ) |
attach an object member function to be called when shaft is rotated clockwise
- Parameters:
-
tptr pointer to object mprt pointer ro member function callback-System for rotation of shaft CCW
attach a function to be called when the shaft is rotated counterclockwise keep this function short, as no interrrupts can occour within
- Parameters:
-
fprt Pointer to callback-function
Definition at line 160 of file mRotaryEncoder.h.
| void attachROTCW | ( | Callback< void()> | cb ) |
attach an object member function to be called when shaft is rotated
- Parameters:
-
tptr pointer to object mprt pointer ro member function callback-System for rotation of shaft CW
attach a function to be called when the shaft is rotated clockwise keep this function short, as no interrrupts can occour within
- Parameters:
-
cb callback-function
Definition at line 134 of file mRotaryEncoder.h.
| void attachSW | ( | Callback< void()> | cb ) |
attach a function to be called when switch is pressed
keep this function short, as no interrrupts can occour within
- Parameters:
-
cb callback-function
Definition at line 85 of file mRotaryEncoder.h.
| int Get | ( | void | ) |
Get the actual value of the rotary position.
- Returns:
- position int value of position
Definition at line 42 of file mRotaryEncoder.cpp.
| void Set | ( | int | value ) |
Set the current position value.
- Parameters:
-
value the new position to set
Definition at line 48 of file mRotaryEncoder.cpp.
Field Documentation
Callback<void()> rotCCWIsr [protected] |
counterclockwise rotated
Definition at line 209 of file mRotaryEncoder.h.
Callback<void()> rotCWIsr [protected] |
clockwise rotated
Definition at line 204 of file mRotaryEncoder.h.
Callback<void()> rotIsr [protected] |
Generated on Sat Jul 16 2022 08:13:14 by
1.7.2