#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include "qrcode.h"
//paramters define
#define MODEL ILI9341
#define TFT_CS 5
#define TFT_DC 4
#define TFT_RST 16
#define TFT_MOSI 23
#define TFT_MISO 19
#define TFT_SCK 18
#define TFT_LED 0 //if you don't need to control the LED pin,you should set it to -1 and set it to 3.3V
//define some colour values
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS,TFT_DC, TFT_RST);
//QRCode qrcode;
void setup() {
Serial.begin(115200);
// Initialize the TFT display
tft.begin();
tft.setRotation(3); // Adjust the rotation if needed
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(4);
// Generate and display QR code
//QRCode qrcode;
String qrData = "http://www.google.com"; // Replace with your QR code data
generateAndDisplayQRCode(qrData);
}
void loop() {
// Nothing to do here
}
void generateAndDisplayQRCode(String qrData) {
QRCode qrcode;
int moduleSize = 6; // Adjust the module size as needed
// Allocate QR code data structure
uint8_t qrcodeData[qrcode_getBufferSize(3)];
// Generate QR code
qrcode_initText(&qrcode, qrcodeData, 3, ECC_MEDIUM, qrData.c_str() );
// Display QR code on the TFT
for (int y = 0; y < qrcode.size; y++) {
for (int x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y)) {
tft.fillRect(x * moduleSize, y * moduleSize, moduleSize, moduleSize, ILI9341_WHITE);
}
}
}
tft.setCursor(20, 200);
tft.println("Scan to Pay");
}