找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 5953|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

QRcode二維碼生成顯示

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
在我們生活中隨處可見(jiàn)二維碼,我們?cè)诹阒迳鲜褂密浖䦷?kù)來(lái)生成并顯示二維碼。
硬件:零知-標(biāo)準(zhǔn)板、OLED(最好用像素更大的LCD)
連線:連線請(qǐng)參照OLED模塊使用教程進(jìn)行。

程序源碼如下:
  1. /**
  2. *  QRCode 零知板-二維碼生成與顯示
  3. * 2018年7月31日16:23:41
  4. *        by 零知實(shí)驗(yàn)室
  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.     // 根據(jù)字符串生成二維碼
  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. }
復(fù)制代碼

最后在OLED上可以看到我們生成的二維碼:


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表