Encoder, switch, temperature signals, potentiometer and LEDs on the Analog Shield. More...
#include <AnalogShield.h>
Public Types | |
| using | EncoderCallback = void (*)(int32_t count, int8_t step) |
| Called on every encoder step. | |
| using | SwitchCallback = void (*)(bool pressed) |
| Called when the encoder switch is pressed or released. | |
Public Member Functions | |
| void | begin () |
| Sets pin modes, turns both LEDs off and starts tracking the encoder and its switch. | |
| void | end () |
| Stops tracking the encoder and its switch. | |
| int32_t | EncoderCount () const noexcept |
| Encoder steps since begin() or the last SetEncoderCount(). | |
| int32_t | EncoderDetents () const noexcept |
| Encoder clicks (detents) since begin() or the last SetEncoderCount(). | |
| void | SetEncoderCount (int32_t count=0) noexcept |
| Sets the encoder count, for example to zero it at a home position. | |
| void | SetEncoderCallback (EncoderCallback callback) noexcept |
| Sets the function called on every encoder step. | |
| bool | SwitchPressed () const noexcept |
| Reads the encoder switch. | |
| void | SetSwitchCallback (SwitchCallback callback) noexcept |
| Sets the function called when the encoder switch is pressed or released. | |
| bool | SetAdcResolution (uint8_t bits) |
| Sets the ADC resolution used by analogRead() and by every reading below. | |
| uint8_t | AdcResolution () const noexcept |
| ADC resolution set by SetAdcResolution(). | |
| void | LedON (uint8_t index, bool on=true) noexcept |
| Turns an LED on or off. | |
| void | LedToggle (uint8_t index) noexcept |
| Toggles an LED. | |
Readings | |
Every reading takes an optional | |
| int | TempRaw (TempSource source, uint8_t samples=1) const |
| Reads a temperature signal with the ADC. | |
| int32_t | TempMillivolts (TempSource source, uint8_t samples=1) const |
| Reads the voltage of a temperature signal. | |
| float | TempCelsius (TempSource source, uint8_t samples=1) const |
| Reads a temperature signal and converts it to degrees Celsius. | |
| float | TempFahrenheit (TempSource source, uint8_t samples=1) const |
| Reads a temperature signal and converts it to degrees Fahrenheit. | |
| float | TempKelvin (TempSource source, uint8_t samples=1) const |
| Reads a temperature signal and converts it to kelvins. | |
| int | PotRaw (uint8_t samples=1) const |
| Reads the potentiometer RV1 with the ADC. | |
| int32_t | PotMillivolts (uint8_t samples=1) const |
| Reads the potentiometer wiper voltage. | |
| float | PotPercent (uint8_t samples=1) const |
| Reads the potentiometer position. | |
Static Public Attributes | |
Encoder resolution (PEC11L-4220F-S0015: 15 pulses, 30 detents per turn) | |
| static constexpr int32_t | COUNTS_PER_DETENT = 2 |
| EncoderCount() steps per click. | |
| static constexpr int32_t | DETENTS_PER_REV = 30 |
| Clicks per full turn. | |
Encoder, switch, temperature signals, potentiometer and LEDs on the Analog Shield.
Create one AnalogShield and call begin() in setup(). The encoder and its switch are tracked with pin interrupts from then on.
| using AnalogShield::EncoderCallback = void (*)(int32_t count, int8_t step) |
Called on every encoder step.
| count | New encoder count, as returned by EncoderCount(). |
| step | +1 when A leads B, -1 when B leads A. |
| using AnalogShield::SwitchCallback = void (*)(bool pressed) |
Called when the encoder switch is pressed or released.
| pressed | true on press, false on release. |
|
nodiscardnoexcept |
ADC resolution set by SetAdcResolution().
| void AnalogShield::begin | ( | ) |
Sets pin modes, turns both LEDs off and starts tracking the encoder and its switch.
Resets the encoder count to 0. Callbacks already set are kept.
|
nodiscardnoexcept |
Encoder steps since begin() or the last SetEncoderCount().
|
nodiscardnoexcept |
Encoder clicks (detents) since begin() or the last SetEncoderCount().
|
noexcept |
Turns an LED on or off.
| index | AnalogShieldPins::LED1 or AnalogShieldPins::LED2; other pins are ignored. |
| on | true to turn the LED on, false to turn it off. |
|
noexcept |
Toggles an LED.
| index | AnalogShieldPins::LED1 or AnalogShieldPins::LED2; other pins are ignored. |
|
nodiscard |
Reads the potentiometer wiper voltage.
| samples | ADC reads to average. |
|
nodiscard |
Reads the potentiometer position.
| samples | ADC reads to average. |
|
nodiscard |
Reads the potentiometer RV1 with the ADC.
| samples | ADC reads to average. |
| bool AnalogShield::SetAdcResolution | ( | uint8_t | bits | ) |
Sets the ADC resolution used by analogRead() and by every reading below.
Use this rather than calling analogReadResolution() directly, so the millivolt and temperature conversions use the same full scale.
| bits | 8 to 12. The RP2040/RP2350 ADC is 12-bit; the Arduino default is 10. |
bits is out of range or the board cannot change resolution (Uno R3 stays at 10 bits).
|
noexcept |
Sets the function called on every encoder step.
| callback | Function to call, or nullptr to remove it. |
|
noexcept |
Sets the encoder count, for example to zero it at a home position.
| count | New count, in EncoderCount() steps. Leave out to reset to 0. |
|
noexcept |
Sets the function called when the encoder switch is pressed or released.
| callback | Function to call, or nullptr to remove it. |
|
nodiscardnoexcept |
|
nodiscard |
Reads a temperature signal and converts it to degrees Celsius.
Undoes the shield's signal path for source (the R15 / 10K divider, with the Phyduino Pico's 100 kΩ A3 pull-down in parallel with R15 for EXT, then the conditioning stage Vout = 4.3 Vin - 0.638 V), then applies the LMT84 parabolic transfer function (datasheet Equation 2). Accurate over the sensor's -50 to 150 °C range; outside it the result is extrapolated.
| source | Signal to read. |
| samples | ADC reads to average. |
|
nodiscard |
Reads a temperature signal and converts it to degrees Fahrenheit.
| source | Signal to read. |
| samples | ADC reads to average. |
|
nodiscard |
Reads a temperature signal and converts it to kelvins.
| source | Signal to read. |
| samples | ADC reads to average. |
|
nodiscard |
Reads the voltage of a temperature signal.
| source | Signal to read. |
| samples | ADC reads to average. |
|
nodiscard |
Reads a temperature signal with the ADC.
| source | Signal to read. |
| samples | ADC reads to average. |