标题:
QRcode二维码生成显示
[打印本页]
作者:
roc2
时间:
2018-7-31 16:39
标题:
QRcode二维码生成显示
在我们生活中随处可见二维码,我们在零知板上使用软件库来生成并显示二维码。
硬件:零知-标准板、OLED(最好用像素更大的LCD)
连线:连线请参照OLED模块使用教程进行。
程序源码如下:
/**
* QRCode 零知板-二维码生成与显示
* 2018年7月31日16:23:41
* by 零知实验室
*
*/
#include <qrcode.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
// Start time
uint32_t dt = millis();
// 根据字符串生成二维码
QRCode qrcode;
uint8_t qrcodeData[qrcode_getBufferSize(3)];
qrcode_initText(&qrcode, qrcodeData, 3, 0, "http://www.lingzhilab.com");
// Delta time
dt = millis() - dt;
Serial.print("QR Code Generation Time: ");
Serial.print(dt);
Serial.print("\n");
// Top quiet zone
Serial.print("\n\n\n\n");
//显示到OLED上
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": " ");
if(qrcode_getModule(&qrcode,x,y)){
display.drawPixel(x, y, WHITE);
}else{
display.drawPixel(x, y, BLACK);
}
}
Serial.print("\n");
}
display.display();
// Bottom quiet zone
Serial.print("\n\n\n\n");
}
void loop() {
}
复制代码
最后在OLED上可以看到我们生成的二维码:
31.jpg
(282.43 KB, 下载次数: 57)
下载附件
2018-7-31 16:39 上传
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1