#include <Arduino.h>
#include <U8g2lib.h>
#include <qrcode.h>
// Setup u8g2 library for SSD1306 OLED
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
// Create a QR code object
QRCode qrcode;
void setup() {
u8g2.begin();
}
void loop() {
u8g2.clearBuffer(); // Clear the internal memory
// Create a string for the QR code
String str = "Hello World";
// Create a char array from the string
char charBuf[str.length() + 1];
str.toCharArray(charBuf, str.length() + 1);
// Generate the QR code
uint8_t qrcodeData[qrcode_getBufferSize(3)];
qrcode_initText(&qrcode, qrcodeData, 3, 0, charBuf);
// Draw the QR code on the OLED
for (uint8_t y = 0; y < qrcode.size; y++) {
for (uint8_t x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y)) {
u8g2.drawBox(x*2, y*2, 2, 2);
}
}
}
u8g2.sendBuffer(); // Transfer internal memory to the display
delay(5000); // Wait for 5 seconds
}