Docs
Volume
The Volume widget sends a level from 0 to 100, drawn like a media control.
Use it for: an amplifier, a buzzer, a speaker board, anything where the user already thinks in terms of volume.
| Setting | What it does |
|---|---|
| Pin | the virtual pin your code reads |
| Min, Max | the range, 0 to 100 by default |
| Send on release | send once when you lift your finger |
Open these from the canvas: tap Edit, then long press the widget and choose Configure.
Example
A volume level driving a digital potentiometer over I2C.
#include <Wire.h>
#include <PlynxSimpleEsp32.h>
#define POT_ADDRESS 0x2C
PLYNX_WRITE(V35)
{
int level = param.asInt(); // 0 to 100
int step = map(level, 0, 100, 0, 127);
Wire.beginTransmission(POT_ADDRESS);
Wire.write(0x00);
Wire.write(step);
Wire.endTransmission();
}
void setup()
{
Serial.begin(115200);
Wire.begin();
// Auto setup: WiFi and the Plynx token are configured from the app.
//
// To provide them directly in the sketch instead, use:
// Plynx.begin(auth, ssid, pass);
Plynx.begin();
}
void loop()
{
Plynx.run();
} map() converts the widget range to whatever your hardware wants. A digital
pot with 128 steps needs 0 to 127, not 0 to 100.
Volume sounds linear and is not. Halving the number does not halve what you hear, so a logarithmic curve in code feels closer to right.
Troubleshooting
| Problem | Check |
|---|---|
| No sound at low settings | the hardware has a floor; map to a narrower range |
| Most of the travel does nothing | the response is logarithmic; convert in code |
| Value stops at 100 | the widget Max, not the sketch |
| I2C writes fail | the device address, and pull-ups on SDA and SCL |