17#define ANALOG_SHIELD_VERSION "0.1.2"
18#define ANALOG_SHIELD_VERSION_MAJOR 0
19#define ANALOG_SHIELD_VERSION_MINOR 1
20#define ANALOG_SHIELD_VERSION_PATCH 2
35constexpr uint8_t
POT = A5;
218 [[nodiscard]]
int PotRaw(uint8_t samples = 1) const;
227 [[nodiscard]] int32_t
PotMillivolts(uint8_t samples = 1) const;
234 [[nodiscard]]
float PotPercent(uint8_t samples = 1) const;
243 void LedON(uint8_t index,
bool on = true) noexcept;
253 static
void OnEncoderA();
255 static
void OnEncoderB();
257 static
void EncoderStep(int8_t step);
259 static
void OnSwitch();
261 [[nodiscard]] static
float ReadAverage(uint8_t pin, uint8_t samples);
263 [[nodiscard]]
float CountsToMillivolts(
float counts, uint8_t pin) const noexcept;
265 [[nodiscard]] static
float MillivoltsToCelsius(
float mv,
TempSource source) noexcept;
270 uint8_t adc_bits = 10;
272 volatile int32_t count = 0;
275 volatile
bool switch_pressed = false;
TempSource
Temperature signal to read with AnalogShield::TempRaw() or AnalogShield::TempMillivolts().
Definition AnalogShield.h:52
@ MCU
Conditioned signal on TEMP_SIG_MCU (A0, RP2040 ADC), JP2 at Internal.
Definition AnalogShield.h:54
@ SENSOR
Raw sensor output on SENSOR_IN (A1).
Definition AnalogShield.h:53
@ EXT
Conditioned signal on TEMP_SIG_EXT (A3, MAX11635 external ADC on the Phyduino Pico),...
Definition AnalogShield.h:55
Encoder, switch, temperature signals, potentiometer and LEDs on the Analog Shield.
Definition AnalogShield.h:64
void(*)(bool pressed) SwitchCallback
Called when the encoder switch is pressed or released.
Definition AnalogShield.h:79
void LedON(uint8_t index, bool on=true) noexcept
Turns an LED on or off.
Definition AnalogShield.cpp:266
void(*)(int32_t count, int8_t step) EncoderCallback
Called on every encoder step.
Definition AnalogShield.h:72
int32_t TempMillivolts(TempSource source, uint8_t samples=1) const
Reads the voltage of a temperature signal.
Definition AnalogShield.cpp:216
static constexpr int32_t DETENTS_PER_REV
Clicks per full turn.
Definition AnalogShield.h:96
void end()
Stops tracking the encoder and its switch.
Definition AnalogShield.cpp:82
void SetEncoderCount(int32_t count=0) noexcept
Sets the encoder count, for example to zero it at a home position.
Definition AnalogShield.cpp:98
float TempKelvin(TempSource source, uint8_t samples=1) const
Reads a temperature signal and converts it to kelvins.
Definition AnalogShield.cpp:248
uint8_t AdcResolution() const noexcept
ADC resolution set by SetAdcResolution().
Definition AnalogShield.cpp:186
int32_t EncoderDetents() const noexcept
Encoder clicks (detents) since begin() or the last SetEncoderCount().
Definition AnalogShield.cpp:95
float TempFahrenheit(TempSource source, uint8_t samples=1) const
Reads a temperature signal and converts it to degrees Fahrenheit.
Definition AnalogShield.cpp:244
float TempCelsius(TempSource source, uint8_t samples=1) const
Reads a temperature signal and converts it to degrees Celsius.
Definition AnalogShield.cpp:240
void SetEncoderCallback(EncoderCallback callback) noexcept
Sets the function called on every encoder step.
Definition AnalogShield.cpp:104
int TempRaw(TempSource source, uint8_t samples=1) const
Reads a temperature signal with the ADC.
Definition AnalogShield.cpp:212
bool SetAdcResolution(uint8_t bits)
Sets the ADC resolution used by analogRead() and by every reading below.
Definition AnalogShield.cpp:171
int32_t EncoderCount() const noexcept
Encoder steps since begin() or the last SetEncoderCount().
Definition AnalogShield.cpp:93
float PotPercent(uint8_t samples=1) const
Reads the potentiometer position.
Definition AnalogShield.cpp:261
int32_t PotMillivolts(uint8_t samples=1) const
Reads the potentiometer wiper voltage.
Definition AnalogShield.cpp:256
int PotRaw(uint8_t samples=1) const
Reads the potentiometer RV1 with the ADC.
Definition AnalogShield.cpp:252
static constexpr int32_t COUNTS_PER_DETENT
EncoderCount() steps per click.
Definition AnalogShield.h:95
void begin()
Sets pin modes, turns both LEDs off and starts tracking the encoder and its switch.
Definition AnalogShield.cpp:56
bool SwitchPressed() const noexcept
Reads the encoder switch.
Definition AnalogShield.cpp:144
void SetSwitchCallback(SwitchCallback callback) noexcept
Sets the function called when the encoder switch is pressed or released.
Definition AnalogShield.cpp:146
void LedToggle(uint8_t index) noexcept
Toggles an LED.
Definition AnalogShield.cpp:272
Shield signals by Arduino pin, from the Rev-C schematic.
Definition AnalogShield.h:26
constexpr uint8_t SENSOR_IN
Raw temperature sensor (JP1: Internal U1 or External J1).
Definition AnalogShield.h:32
constexpr uint8_t ENC_SW
Rotary encoder push switch, active low (pulled up to VDD).
Definition AnalogShield.h:40
constexpr uint8_t LED1
D1 green LED, active low (anode to VDD).
Definition AnalogShield.h:44
constexpr uint8_t IR_VOUT
Sharp GP2Y0A21YK0F IR distance sensor (J2).
Definition AnalogShield.h:34
constexpr uint8_t LED2
D2 red LED, active low (anode to VDD).
Definition AnalogShield.h:43
constexpr uint8_t TEMP_SIG_EXT
Conditioned temperature signal, JP2 at External (MAX11635 ADC on the Phyduino Pico).
Definition AnalogShield.h:33
constexpr uint8_t ENC_B
Rotary encoder channel B, active low (pulled up to VDD).
Definition AnalogShield.h:42
constexpr uint8_t POT
Potentiometer RV1 wiper (0 V to VDD).
Definition AnalogShield.h:35
constexpr uint8_t TEMP_SIG_MCU
Conditioned temperature signal, JP2 at Internal (RP2040 ADC).
Definition AnalogShield.h:31
constexpr uint8_t ENC_A
Rotary encoder channel A, active low (pulled up to VDD).
Definition AnalogShield.h:41