#include <Wire.h>
#include <U8glib.h>
#include <qrcode.h>
#define OLED_WIDTH 128
#define OLED_HEIGHT 64
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);
void setup() {
u8g.begin();
u8g.setFont(u8g_font_unifont);
}
void loop() {
// UPI payment parameters
const char* payeeVPA = "abhishekgn985@okaxis"; // Replace with the payee's VPA
double amount = 50.00; // Replace with the payment amount as a double
const char* currency = "INR"; // Replace with the currency code
// Generate and display the QR code for UPI payment
displayQRCode(payeeVPA, amount, currency);
delay(5000); // Display for 5 seconds before generating a new QR code
}
void displayQRCode(const char* payeeVPA, double amount, const char* currency) {
// Construct the UPI payment link
String upiLink = "upi://pay?pa=" + String(payeeVPA) + "&am=" + String(amount, 2) + "&cu=" + String(currency); // 2 decimal places for the amount
QRCode qrcode;
uint8_t qrcodeData[qrcode_getBufferSize(3)];
qrcode_initText(&qrcode, qrcodeData, 3, 0, upiLink.c_str());
int scale = min(OLED_WIDTH / qrcode.size, OLED_HEIGHT / qrcode.size);
int shiftX = (OLED_WIDTH - qrcode.size * scale) / 2;
int shiftY = (OLED_HEIGHT - qrcode.size * scale) / 2;
u8g.firstPage();
do {
drawQRCode(qrcode, scale, shiftX, shiftY);
} while (u8g.nextPage());
}
void drawQRCode(QRCode &qrcode, int scale, int shiftX, int shiftY) {
for (uint8_t y = 0; y < qrcode.size; y++) {
for (uint8_t x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y)) {
u8g.drawBox(x * scale + shiftX, y * scale + shiftY, scale, scale);
}
}
}
}