Skip to content

Channels

The channels element displays values as bars for each channel.

Configure

Warning

Ensure the graphics library is included and initialised according to the configuration procedure.

Channels myChannels(&myGraphics);

The constructor Channels() creates a channels element and sets the link to the graphics myGraphics.

1
2
3
4
myChannels.dDefine(0, dy, x, dy * 3, // x0 y0 dx dy
    0, 200, unit, // valueMin valueMax unit
    3, 4, // channels sectionsY
    myColours.black); // value colour

The required parameters are

  • The first line sets the x-y coordinates and the width and height of the graphic;

  • The second line sets the minimum, maximum and unit for the values.

The optional parameters are

  • The third line sets the number of channels on the x-axis and splits the y-axis into a given number of sections;

  • The fourth line specifies the colour for the value.

Note

For monochrome and colour e-paper screens, ensure the selected colours are supported.

Use

myChannels.draw(channel, value);

draw() sends the new value to the channel, with channel a 0-based index.

Example

This is the core of the code from example Graphics_Channels.ino.

void displayChannels()
{
    myScreen.setOrientation(myOrientation);
    myScreen.clear();
    uint16_t x = myScreen.screenSizeX();
    uint16_t y = myScreen.screenSizeY();
    uint16_t dx = x / 3;
    uint16_t dy = y / 5;

    myScreen.selectFont(fontLarge);
    myScreen.gText(0, 0, "Channels");

    Channels myChannels(&myGraphics);
    int32_t unit = 100;
    myChannels.dDefine(0, dy, x, dy * 3, // x0 y0 dx dy
                       0, 200, unit, // min max unit
                       3, 4, // channels sectionsY
                       myColours.black); // value colours

    int32_t value0 = 0;
    int32_t value1 = 0;
    int32_t value2 = 0;
    uint8_t formatUnit = getDecimalPlaces(unit);

    myScreen.setFontSolid(true);
    for (int32_t count = 0; count < 201; count += 25)
    {
        value0 = count;
        value2 = 200 - count;
        value1 = abs(value0 - value2);

        myChannels.draw(0, value0);
        myScreen.gText(0, dy * 4, formatString(" %+i.%0*i ", value0 / unit, formatUnit, abs(value0) % unit), myColours.black, myColours.white);
        myChannels.draw(1, value1);
        myScreen.gText(dx, dy * 4, formatString(" %+i.%0*i ", value1 / unit, formatUnit, abs(value1) % unit), myColours.black, myColours.white);
        myChannels.draw(2, value2);
        myScreen.gText(dx * 2, dy * 4, formatString(" %+i.%0*i ", value2 / unit, formatUnit, abs(value2) % unit), myColours.black, myColours.white);

        myScreen.flushFast();
    }
}