Components and supplies
Arduino UNO
ILI9341
Apps and platforms
Arduino IDE
ricmoo/QRCode Library
LCDWIKI Library
Project description
Code
qrcode_ILI9341.ino
arduino
1#include <LCDWIKI_GUI.h> //Core graphics library 2#include <LCDWIKI_SPI.h> //Hardware-specific library 3#include "qrcode.h" 4 5//paramters define 6#define MODEL ILI9341 7#define CS A5 8#define CD A3 9#define RST A4 10#define MOSI 11 11#define MISO 12 12#define SCK 13 13#define LED A0 //if you don't need to control the LED pin,you should set it to -1 and set it to 3.3V 14 15//the definiens of software spi mode as follow: 16//if the IC model is known or the modules is unreadable,you can use this constructed function 17LCDWIKI_SPI mylcd(MODEL,CS,CD,MISO,MOSI,RST,SCK,LED); //model,cs,dc,miso,mosi,reset,sck,led 18//if the IC model is not known and the modules is readable,you can use this constructed function 19//LCDWIKI_SPI mylcd(240,320,CS,CD,MISO,MOSI,RST,SCK,LED); //width,height,cs,dc,miso,mosi,reset,sck,led 20 21//define some colour values 22#define BLACK 0x0000 23#define BLUE 0x001F 24#define RED 0xF800 25#define GREEN 0x07E0 26#define CYAN 0x07FF 27#define MAGENTA 0xF81F 28#define YELLOW 0xFFE0 29#define WHITE 0xFFFF 30 31int16_t xaxis=0, yaxis=0, w, h; 32 33void setup() { 34 Serial.begin(9600); 35 mylcd.Init_LCD(); 36 w = mylcd.Get_Display_Width(); 37 h = mylcd.Get_Display_Height(); 38 xaxis = w/2; 39 yaxis = h/2; 40 mylcd.Set_Text_Mode(0); 41} 42 43void loop() { 44 mylcd.Fill_Screen(BLACK); 45 generateQRCode(); 46} 47 48void generateQRCode() { 49 // Create the QR code 50 QRCode qrcode; 51 String amount = "https://youtu.be/jDbdt7-aDDE"; 52 uint32_t str_len = amount.length() + 1; 53 char am[str_len]; 54 amount.toCharArray(am, str_len); 55 char *data = am; 56 57 const uint8_t ecc = 0; //lowest level of error correction 58 const uint8_t version = 3; 59 60 uint8_t qrcodeData[qrcode_getBufferSize(version)]; 61 qrcode_initText(&qrcode, 62 qrcodeData, 63 version, ecc, 64 data); 65 const int xy_scale = 6; 66 int xmax = w/2; 67 int ymax = h/2; 68 int offset = (xy_scale*qrcode.size); 69 int x1 = xmax - (offset/2); 70 int y1 = ymax - (offset/2); 71 72 int px1 = x1; 73 int py1 = x1; 74 int px2 = px1; 75 int py2 = py1; 76 77// // Top quiet zone 78 for (uint8_t y = 0; y < qrcode.size; y++) { 79 for (uint8_t x = 0; x < qrcode.size; x++) { 80 bool mod = qrcode_getModule(&qrcode, x, y); 81 px1 = x1 + x * xy_scale; 82 py1 = x1 + y * xy_scale; 83 px2 = px1 + xy_scale; 84 py2 = py1 + xy_scale; 85 if(mod){ 86 mylcd.Set_Draw_color(CYAN); 87 mylcd.Fill_Rectangle(px1, py1, px2, py2); 88 } 89 } 90 } 91 92} 93
qrcode_ILI9341.ino
arduino
1#include <LCDWIKI_GUI.h> //Core graphics library 2#include <LCDWIKI_SPI.h> //Hardware-specific library 3#include "qrcode.h" 4 5//paramters define 6#define MODEL ILI9341 7#define CS A5 8#define CD A3 9#define RST A4 10#define MOSI 11 11#define MISO 12 12#define SCK 13 13#define LED A0 //if you don't need to control the LED pin,you should set it to -1 and set it to 3.3V 14 15//the definiens of software spi mode as follow: 16//if the IC model is known or the modules is unreadable,you can use this constructed function 17LCDWIKI_SPI mylcd(MODEL,CS,CD,MISO,MOSI,RST,SCK,LED); //model,cs,dc,miso,mosi,reset,sck,led 18//if the IC model is not known and the modules is readable,you can use this constructed function 19//LCDWIKI_SPI mylcd(240,320,CS,CD,MISO,MOSI,RST,SCK,LED); //width,height,cs,dc,miso,mosi,reset,sck,led 20 21//define some colour values 22#define BLACK 0x0000 23#define BLUE 0x001F 24#define RED 0xF800 25#define GREEN 0x07E0 26#define CYAN 0x07FF 27#define MAGENTA 0xF81F 28#define YELLOW 0xFFE0 29#define WHITE 0xFFFF 30 31int16_t xaxis=0, yaxis=0, w, h; 32 33void setup() { 34 Serial.begin(9600); 35 mylcd.Init_LCD(); 36 w = mylcd.Get_Display_Width(); 37 h = mylcd.Get_Display_Height(); 38 xaxis = w/2; 39 yaxis = h/2; 40 mylcd.Set_Text_Mode(0); 41} 42 43void loop() { 44 mylcd.Fill_Screen(BLACK); 45 generateQRCode(); 46} 47 48void generateQRCode() { 49 // Create the QR code 50 QRCode qrcode; 51 String amount = "https://youtu.be/jDbdt7-aDDE"; 52 uint32_t str_len = amount.length() + 1; 53 char am[str_len]; 54 amount.toCharArray(am, str_len); 55 char *data = am; 56 57 const uint8_t ecc = 0; //lowest level of error correction 58 const uint8_t version = 3; 59 60 uint8_t qrcodeData[qrcode_getBufferSize(version)]; 61 qrcode_initText(&qrcode, 62 qrcodeData, 63 version, ecc, 64 data); 65 const int xy_scale = 6; 66 int xmax = w/2; 67 int ymax = h/2; 68 int offset = (xy_scale*qrcode.size); 69 int x1 = xmax - (offset/2); 70 int y1 = ymax - (offset/2); 71 72 int px1 = x1; 73 int py1 = x1; 74 int px2 = px1; 75 int py2 = py1; 76 77// // Top quiet zone 78 for (uint8_t y = 0; y < qrcode.size; y++) { 79 for (uint8_t x = 0; x < qrcode.size; x++) { 80 bool mod = qrcode_getModule(&qrcode, x, y); 81 px1 = x1 + x * xy_scale; 82 py1 = x1 + y * xy_scale; 83 px2 = px1 + xy_scale; 84 py2 = py1 + xy_scale; 85 if(mod){ 86 mylcd.Set_Draw_color(CYAN); 87 mylcd.Fill_Rectangle(px1, py1, px2, py2); 88 } 89 } 90 } 91 92} 93
Downloadable files
untitled
untitled
Comments
Only logged in users can leave comments