Energy Card
This feature is only available in ESP-DASH Pro
The Energy Card displays energy consumption values with a configurable unit.
Initializer
To create an energy card in ESP-DASH v5, use the dash::EnergyCard<T, Precision> class. The template parameters allow you to control the value type and decimal precision:
T: Value type (e.g., float, int)Precision: Number of decimal places for floating point values (default: 2)
Example 1: Float value, default precision (2 decimals)
dash::EnergyCard<float> energy(dashboard, "Energy Consumption", "kWh");Example 2: Float value, custom precision (3 decimals)
dash::EnergyCard<float, 3> energy3(dashboard, "Energy Consumption", "Joule");Example 3: Integer value
dash::EnergyCard<int> energyInt(dashboard, "Energy Consumption", "Wh");Methods
setValue(T value)
Set the energy value. The type of value must match the template type you chose for T (e.g., int, float).
energy.setValue(value); // value is of type T- Signature:
void setValue(T value) - Parameters:
T value— The value to display (type matches template parameterT).
- Returns:
void
value()
Get the current energy value. The return type matches your template type for T (e.g., int, float).
T v = energy.value();- Signature:
T value() - Parameters: None
- Returns:
T— The current value displayed by the card (type matches template parameterT).
Note:
Tcan be one of:intorfloatdepending on how you instantiate the card.
setUnit(const char* unit)
Set the unit or symbol for the energy card.
energy.setUnit("Joule");- Signature:
void setUnit(const char* unit) - Parameters:
const char* unit— The unit or symbol to display.
- Returns:
void
unit()
Get the unit or symbol for the energy card.
const char* unit = energy.unit();- Signature:
const char* unit() - Parameters: None
- Returns:
const char*— The current unit or symbol for the card.
Reference
Below is a reference code showing how to integrate this widget in a real project, including initialization and value updates usage.
// ...
// Create an energy card (float, 2 decimals by default)
dash::EnergyCard<float> energyCard(dashboard, "Energy Consumption", "kWh");
void setup() {
// ...
energyCard.setValue(123.4f);
energyCard.setUnit("Joule");
}
void loop() {
// ...
}Last updated on