#include "qrcode.h"
const int QRcode_Version = 6; // set the version (range 1->40)
const int QRcode_ECC = 0; // set the Error Correction level (range 0-3) or symbolic (ECC_LOW, ECC_MEDIUM, ECC_QUARTILE and ECC_HIGH)
QRCode qrcode; // Create the QR code
#include <U8g2lib.h>
// U8g2 Contructor List for Frame Buffer Mode.
// This uses the Hardware I2C peripheral on ESP8266 with DMA interface
// The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
#define Lcd_X 128
#define Lcd_Y 64
void setup() {
Serial.begin(115200);
u8g2.begin();
u8g2.clearBuffer();
u8g2.setContrast(220); // set OELD brightness(0->255)
//u8g2.setFont(u8g2_font_ncenB12_tr ); // 12 pixel height
//u8g2.setFont(u8g2_font_ncenB08_tr); // 8 pixel height
//u8g2.setFont(u8g2_font_9x15_tf ); // 10 pixel height
u8g2.setFont(u8g2_font_6x13_te ); // 9 pixel height
u8g2.drawStr(0, 12, "Generating QR Code"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
// Start time
uint32_t dt = millis();
//--------------------------------------------
// Allocate memory to store the QR code.
// memory size depends on version number
uint8_t qrcodeData[qrcode_getBufferSize(QRcode_Version)];
//--------------------------------------------
//configure the text string to code
// qrcode_initText(&qrcode, qrcodeData, QRcode_Version, QRcode_ECC, "{\"a\":\"DE6os4N86ef9bba6kVGurqxmhpBHKctoxY\"}"); //dARK address
//qrcode_initText(&qrcode, qrcodeData, QRcode_Version, QRcode_ECC, "DE6os4N86ef9bba6kVGurqxmhpBHKctoxY"); //dARK address
qrcode_initText(&qrcode, qrcodeData, QRcode_Version, QRcode_ECC, "ark:AePNZAAtWhLsGFLXtztGLAPnKm98VVC8tJ?amount=20.3"); //ARK address
// qrcode_initText(&qrcode, qrcodeData, QRcode_Version, QRcode_ECC, "hello pj");
//qrcode_initText(&qrcode, qrcodeData, QRcode_Version, QRcode_ECC, "1BGJvqAuZvr23EixA65PEe5PMLAjVTeyMn"); //bitcoin address
//--------------------------------------------
// Print Code Generation Time
dt = millis() - dt;
Serial.print("QR Code Generation Time: ");
Serial.print(dt);
Serial.print("\n");
//--------------------------------------------
// This prints the QR code to the serial monitor as solid blocks. Each module
// is two characters wide, since the monospace font used in the serial monitor
// is approximately twice as tall as wide.
// Top quiet zone
Serial.print("\n\n\n\n");
for (uint8_t y = 0; y < qrcode.size; y++) {
// Left quiet zone
Serial.print(" ");
// Each horizontal module
for (uint8_t x = 0; x < qrcode.size; x++) {
// Print each module (UTF-8 \u2588 is a solid block)
Serial.print(qrcode_getModule(&qrcode, x, y) ? "\u2588\u2588" : " ");
}
Serial.print("\n");
}
// Bottom quiet zone
Serial.print("\n\n\n\n");
//--------------------------------------------
//display generation time to OLED display
u8g2.drawStr(0, 30, "Generation Time(ms)"); // write something to the internal memory
u8g2.setCursor(0, 50);
u8g2.print(dt); // display time it took to generate code
u8g2.sendBuffer();
delay(3000);
//--------------------------------------------
//Turn on all pixels
for (uint8_t y = 0; y < 63; y++) {
for (uint8_t x = 0; x < 127; x++) {
u8g2.setDrawColor(1); //change 0 to make QR code with black background
u8g2.drawPixel(x, y);
}
}
//uint8_t x0 = (Lcd_X - qrcode.size) / 2;
//uint8_t y0 = (Lcd_Y - qrcode.size) / 2;
//--------------------------------------------
//setup the top left corner of the QRcode
uint8_t x0 = 40;
uint8_t y0 = 10; //16 is the start of the blue portion OLED in the yellow/blue split 64x128 OLED
//--------------------------------------------
//display QRcode
for (uint8_t y = 0; y < qrcode.size; y++) {
for (uint8_t x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y) == 0) { //change to == 1 to make QR code with black background
u8g2.setDrawColor(1);
//uncomment to display code in normal size
u8g2.drawPixel(x0 + x, y0 + y);
//uncomment to double the QRcode
//u8g2.drawPixel(x0 + 2 * x, y0 + 2 * y);
// u8g2.drawPixel(x0 + 2 * x + 1, y0 + 2 * y);
//u8g2.drawPixel(x0 + 2 * x, y0 + 2 * y + 1);
//u8g2.drawPixel(x0 + 2 * x + 1, y0 + 2 * y + 1);
} else {
u8g2.setDrawColor(0);
//uncomment to display code in normal size
u8g2.drawPixel(x0 + x, y0 + y);
//uncomment to double the QRcode
//u8g2.drawPixel(x0 + 2 * x, y0 + 2 * y);
//u8g2.drawPixel(x0 + 2 * x + 1, y0 + 2 * y);
//u8g2.drawPixel(x0 + 2 * x, y0 + 2 * y + 1);
//u8g2.drawPixel(x0 + 2 * x + 1, y0 + 2 * y + 1);
}
}
}
u8g2.sendBuffer();
}
void loop() {
delay(6000);
u8g2.setContrast(1); //dim display
}