Skip to content

QR-code

The QR-code turns a text into a 2D QR-code.

Configure

Ensure the QR-code library is included and initialised according to the configuration procedure.

Warning

This library requires the external QRcode library to generate the patterns.

Ensure the external QRcode library is installed and properly configured.

As a function, the QR-code element requires no configuration.

Use

1
2
3
4
result = codeQR(&myScreen,
    (x - dz) / 2, (y - dz) / 2,
    "www.pervasivedisplays.com",
    2);

The required parameters are

  • The first line sets the link to the screen;

  • The second line sets the x-y coordinates of the top-left corner of the code-bar;

  • The third line provides the text.

The optional parameter is

  • The fourth line sets the multiplier, with 2 as default. This ensures a good readability, as resolution exceeds 100 dpi.

The generated QR-code handles up to 68 characters in a 43-pixel square.

codeQR returns true if successful, false otherwise. The most common cause of error is an overflow due to a text too long.

uint16_t dz = getSizeCodeQR(2);

getCodeBar39Size() returns the size of the square of the QR-code in pixels.

Example

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

void displayCodeQR()
{
    myScreen.setOrientation(myOrientation);

    uint16_t x, y, dx, dy, dz;
    bool result;

    x = myScreen.screenSizeX();
    y = myScreen.screenSizeY();
    dx = x / 5;
    dy = y / 5;

    myScreen.selectFont(fontMedium);
    myScreen.gText(0, 0, "QR-code");

    myScreen.selectFont(fontMedium);

    dz = getQRcodeSize(2);
    myScreen.setFontSolid(true);
    myScreen.gText(0, 4 * dy, formatString("Multiplier=%ix Size= %i pixels", 2, dz), myColours.black, myColours.white);

    result = codeQR(&myScreen, (x - dz) / 2, (y - dz) / 2, "www.pervasivedisplays.com", 2);

    if (result)
    {
        myScreen.flushFast();
    }
}
Back to top