Arduino--二维码显示

(1)简介

随着数字化发展,二维码在生活中的使用率越来越高,本文就基于Arduino控制器生成二维码并在液晶屏幕上显示出来,扫描后会跳转到指定的网页,二维码的显示内容可任意修改。
本文使用0.96寸OLED液晶显示屏,如下图所示:
在这里插入图片描述

(2)接线

Arduino控制器使用的是UNO,0.96寸OLED液晶显示屏使用的是IIC接口,接线方式如下表所示:

0.96 OLED屏UNO
VCC5V
GNDGND
SCLA5
SDAA4
(3)主程序(完整代码及函数头文件见文末链接)
  qrcode_initText(&qrcode, qrcodeData, 3 , ECC_LOW, "https://www.baidu.com");

  // start draw
  u8g2.firstPage();
  do {
    // get the draw starting point,128 and 64 is screen size
    uint8_t x0 = (128 - qrcode.size * 2) / 2;
    uint8_t y0 = (64 - qrcode.size * 2) / 2;
    
    // get QR code pixels in a loop
    for (uint8_t y = 0; y < qrcode.size; y++) {
      for (uint8_t x = 0; x < qrcode.size; x++) {
        // Check this point is black or white
        if (qrcode_getModule(&qrcode, x, y)) {
          u8g2.setColorIndex(1);
        } else {
          u8g2.setColorIndex(0);
        }
        // Double the QR code pixels
        u8g2.drawPixel(x0 + x * 2, y0 + y * 2);
        u8g2.drawPixel(x0 + 1 + x * 2, y0 + y * 2);
        u8g2.drawPixel(x0 + x * 2, y0  + 1 + y * 2);
        u8g2.drawPixel(x0 + 1 + x * 2, y0 + 1 + y * 2);
      }
    }

  } while ( u8g2.nextPage() );
(4)结果展示

在这里插入图片描述

Arduino 二维码显示

完整代码链接:

CSDN下载
https://download.csdn.net/download/u011816009/85853632

百度网盘下载
https://pan.baidu.com/s/1ZBKVnUjwMuV9iGCcO1e33w
提取码:ypae

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

541板哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值