-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqrgenerate.cpp
70 lines (64 loc) · 1.78 KB
/
qrgenerate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <Arduino.h>
#include "qrencode.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <ESP_NETPIE_Adafruit_SSD1306.h>
extern Adafruit_SSD1306 display;
extern int pxSize;
extern int offsetsX;
extern int offsetsY;
void render(int x, int y, int color){
x=x+offsetsX;
y=y+offsetsY;
if(color==1) {
display.drawPixel(x, y, BLACK);
display.drawPixel(x, y+1, BLACK);
display.drawPixel(x+1, y, BLACK);
display.drawPixel(x+1, y+1, BLACK);
}
else {
display.drawPixel(x, y, WHITE);
display.drawPixel(x, y+1, WHITE);
display.drawPixel(x+1, y, WHITE);
display.drawPixel(x+1, y+1, WHITE);
}
}
void createQR(String message) {
// new line
// Serial.println();
// create QR code
message.toCharArray((char *)strinbuf,47);
qrencode();
// print QR Code
for (byte x = 0; x < WD; x+=2) {
for (byte y = 0; y < WD; y++) {
if ( QRBIT(x,y) && QRBIT((x+1),y)) {
// black square on top of black square
// Serial.print("8");
render(x*pxSize, y*pxSize, 0);
render((x+1)*pxSize, y*pxSize, 0);
}
if (!QRBIT(x,y) && QRBIT((x+1),y)) {
// white square on top of black square
// Serial.print(" ");
render(x*pxSize, y*pxSize, 1);
render((x+1)*pxSize, y*pxSize, 0);
}
if ( QRBIT(x,y) && !QRBIT((x+1),y)) {
// black square on top of white square
// Serial.print("8");
render(x*pxSize, y*pxSize, 0);
render((x+1)*pxSize, y*pxSize, 1);
}
if (!QRBIT(x,y) && !QRBIT((x+1),y)) {
// white square on top of white square
// Serial.print(" ");
render(x*pxSize, y*pxSize, 1);
render((x+1)*pxSize, y*pxSize, 1);
}
}
// Serial.println(); // next line
}
// new line
// Serial.println();
}