#include "qrcode.h" //https://github.com/ricmoo/qrcode/
#include <Adafruit_SSD1306.h>
// Color definitions
#define BLACK 0
#define WHITE 1
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
//### slc/sda d1/d2
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
//#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display(128, 64, &Wire, -1);
QRCode qrcode;
int qr_version,xmax, ymax, xa, ya;
void display_qrcode(char *text, int qr_version=2, int qr_quality =ECC_LOW, float scale=1) {
// https://github.com/ricmoo/QRCode
display.clearDisplay();
//size maximum for one qrcode
xmax= 64; ymax = 64;
int inv = 0;
uint8_t qrcodeData[qrcode_getBufferSize(qr_version)]; //Version 4 114 byte 33x33 res QR code
qrcode_initText(&qrcode, qrcodeData, qr_version, qr_quality, text);
// scale = 2;
xa = (xmax - qrcode.size * scale) / 2;
ya = (ymax - qrcode.size * scale) / 2;
inv = 1;
display.fillRect(0, 0, xmax, ymax, abs(inv - BLACK));
for (uint8_t y = 0; y < qrcode.size * scale; y = y + scale) {
for (uint8_t x = 0; x < qrcode.size * scale; x = x + scale) {
if (qrcode_getModule(&qrcode, x / scale, y / scale))
display.fillRect(xa + x, ya + y, scale, scale, abs(inv - WHITE));
}
}
xa = xa + xmax;
inv = 0;
display.fillRect(xmax, 0, xmax, ymax, abs(inv - BLACK));
for (uint8_t y = 0; y < qrcode.size * scale; y = y + scale) {
for (uint8_t x = 0; x < qrcode.size * scale; x = x + scale) {
if (qrcode_getModule(&qrcode, x / scale, y / scale))
display.fillRect(xa + x, ya + y, scale, scale, abs(inv - WHITE));
}
}
display.display();
}
void setup_display(){
// set display
display.begin(SSD1306_SWITCHCAPVCC, 0x78>>1);
display.dim(29);
}
void setup() {
setup_display();
//display_qrcode("http://192.168.2.106", 1, ECC_HIGH, 3);
display_qrcode("http://shorturl.at/oBN04", 3, ECC_LOW, 2);
//display_qrcode(char *text, int qr_version=2, int qr_quality =ECC_LOW, float scale=1)
// display_qrcode("192.168.2.106", 2);
}
void loop() {
}