找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5222|回复: 0
打印 上一主题 下一主题
收起左侧

QRcode二维码生成显示

[复制链接]
跳转到指定楼层
楼主
在我们生活中随处可见二维码,我们在零知板上使用软件库来生成并显示二维码。
硬件:零知-标准板、OLED(最好用像素更大的LCD)
连线:连线请参照OLED模块使用教程进行。

程序源码如下:
  1. /**
  2. *  QRCode 零知板-二维码生成与显示
  3. * 2018年7月31日16:23:41
  4. *        by 零知实验室
  5. *
  6. */

  7. #include <qrcode.h>
  8. #include <Adafruit_SSD1306.h>

  9. #define OLED_RESET 4
  10. Adafruit_SSD1306 display(OLED_RESET);

  11. void setup() {
  12.     Serial.begin(9600);
  13.         
  14.         display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  15.         display.clearDisplay();

  16.     // Start time
  17.     uint32_t dt = millis();
  18.   
  19.     // 根据字符串生成二维码
  20.     QRCode qrcode;
  21.     uint8_t qrcodeData[qrcode_getBufferSize(3)];
  22.     qrcode_initText(&qrcode, qrcodeData, 3, 0, "http://www.lingzhilab.com");
  23.   
  24.     // Delta time
  25.     dt = millis() - dt;
  26.     Serial.print("QR Code Generation Time: ");
  27.     Serial.print(dt);
  28.     Serial.print("\n");

  29.     // Top quiet zone
  30.     Serial.print("\n\n\n\n");
  31.         

  32.         //显示到OLED上
  33.     for (uint8_t y = 0; y < qrcode.size; y++) {

  34.         // Left quiet zone
  35.         Serial.print("        ");

  36.         // Each horizontal module
  37.         for (uint8_t x = 0; x < qrcode.size; x++) {

  38.             // Print each module (UTF-8 \u2588 is a solid block)
  39.             //Serial.print(qrcode_getModule(&qrcode, x, y) ? "\u2588\u2588": "  ");
  40.                         
  41.                         if(qrcode_getModule(&qrcode,x,y)){
  42.                                 display.drawPixel(x, y, WHITE);
  43.                         }else{
  44.                                 display.drawPixel(x, y, BLACK);
  45.                         }

  46.         }

  47.         Serial.print("\n");
  48.     }
  49.         
  50.         display.display();

  51.     // Bottom quiet zone
  52.     Serial.print("\n\n\n\n");
  53. }

  54. void loop() {

  55. }
复制代码

最后在OLED上可以看到我们生成的二维码:


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表