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.
RotaryEncoder Class Reference
Incremental rotary encoder with a push button. More...
#include <RotaryEncoder.h>
Public Member Functions | |
| RotaryEncoder (PinName a, PinName b, PinName sw, PinMode pullMode) | |
| Create an Incremental Rotary Encoder, connected to the specified DT and CLK pins. | |
| void | SetRange (double min, double max) |
| Sets the range in which the global variable Value is limited. | |
Data Fields | |
| double | Value |
| This global class variable stores the current value. | |
| float | Resolution |
| This global class variable is used to set the resolution with which the value is incremented, e.g., Value+=Resolution. | |
Detailed Description
Incremental rotary encoder with a push button.
Can be used as only an incremental rotary encoder, with/without a pushbutton and the PinMode can be set if needed.
Example:
#include "RotaryEncoder.h" RotaryEncoder re(p5, p6); // Default //RotaryEncoder re(p5, p6, PullDown); // With pull mode specified //RotaryEncoder re(p5, p6, p7); // With Switch //RotaryEncoder re(p5, p6, p7, PullDown); // Switch + pull mode specified Serial pc(USBTX, USBRX); // Serial PC connection int main(){ double value = re.Value; pc.printf("\nEncoder program started!"); while(1){ if(value!=re.Value){ pc.printf("\nEncoder value is: %2.f", re.Value); value = re.Value; } wait_ms(1000); } }
Rotary encoder with one interrupt and one digital input
Definition at line 62 of file RotaryEncoder.h.
Constructor & Destructor Documentation
| RotaryEncoder | ( | PinName | a, |
| PinName | b, | ||
| PinName | sw, | ||
| PinMode | pullMode | ||
| ) |
Create an Incremental Rotary Encoder, connected to the specified DT and CLK pins.
- Parameters:
-
a - Data transmition (DT) pin b - Clock (CLK) pin sw - Switch (SW) pin
- Note:
- PullMode can be added on the end of the constructor,
Definition at line 43 of file RotaryEncoder.cpp.
Member Function Documentation
| void SetRange | ( | double | min, |
| double | max | ||
| ) |
Sets the range in which the global variable Value is limited.
- Parameters:
-
min - minimal value max - maximal value
Definition at line 81 of file RotaryEncoder.cpp.
Field Documentation
| float Resolution |
This global class variable is used to set the resolution with which the value is incremented, e.g., Value+=Resolution.
Definition at line 82 of file RotaryEncoder.h.
| double Value |
This global class variable stores the current value.
Definition at line 77 of file RotaryEncoder.h.
Generated on Fri Jul 29 2022 10:03:48 by
1.7.2