From af1d934ff1fced5e9bef0470d20e1732143ccd75 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 20 Mar 2022 14:16:14 -0400 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Arduino=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84example=20=E9=83=A8=E5=88=86=E6=BA=90=E8=87=AA?= =?UTF-8?q?=EF=BC=9Ahttps://github.com/ricmoo/QRCode/pull/12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Meco Man <920369182@qq.com> --- examples/QRCode/QRCode.ino | 56 ++++++++++++++++++++++ examples/QRCode/QRCode_halfsize.ino | 72 +++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 examples/QRCode/QRCode.ino create mode 100644 examples/QRCode/QRCode_halfsize.ino diff --git a/examples/QRCode/QRCode.ino b/examples/QRCode/QRCode.ino new file mode 100644 index 0000000..9f6a655 --- /dev/null +++ b/examples/QRCode/QRCode.ino @@ -0,0 +1,56 @@ +/** + * QRCode + * + * A quick example of generating a QR code. + * + * This prints the QR code to the serial monitor as solid blocks. Each module + * is two characters wide, since the monospace font used in the serial monitor + * is approximately twice as tall as wide. + * + */ + +#include "qrcode.h" + +void setup() { + Serial.begin(115200); + + // Start time + uint32_t dt = millis(); + + // Create the QR code + QRCode qrcode; + uint8_t qrcodeData[qrcode_getBufferSize(3)]; + qrcode_initText(&qrcode, qrcodeData, 3, 0, "HELLO WORLD"); + + // 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"); + + 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": " "); + + } + + Serial.print("\n"); + } + + // Bottom quiet zone + Serial.print("\n\n\n\n"); +} + +void loop() { + +} diff --git a/examples/QRCode/QRCode_halfsize.ino b/examples/QRCode/QRCode_halfsize.ino new file mode 100644 index 0000000..c3045b6 --- /dev/null +++ b/examples/QRCode/QRCode_halfsize.ino @@ -0,0 +1,72 @@ +/** + * QRCode + * + * A quick example of generating a QR code. + * + * This prints the QR code to the serial monitor as solid blocks. Each character + * contains two blocks, since the monospace font used in the serial monitor + * is approximately twice as tall as wide. + * + */ + +#include "qrcode.h" + +void setup() { + Serial.begin(115200); + + // Start time + uint32_t dt = millis(); + + // Create the QR code + QRCode qrcode; + uint8_t qrcodeData[qrcode_getBufferSize(3)]; + qrcode_initText(&qrcode, qrcodeData, 3, 0, "HELLO WORLD"); + + // 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"); + + for (uint8_t y = 0; y < qrcode.size; y += 2) { + + // Left quiet zone + Serial.print(" "); + + // Each horizontal module + for (uint8_t x = 0; x < qrcode.size; x++) { + uint8_t block = qrcode_getModule(&qrcode, x, y) << 1 | qrcode_getModule(&qrcode, x, y + 1); + + switch (block) + { + case 0b00: + Serial.print(" "); + break; + + case 0b01: + Serial.print("\u2584"); // \u2584 lower block + break; + + case 0b10: + Serial.print("\u2580"); // \u2580 upper block + break; + + case 0b11: + Serial.print("\u2588"); // \u2588 both blocks + break; + } + } + + Serial.print("\n"); + } + + // Bottom quiet zone + Serial.print("\n\n\n\n"); +} + +void loop() { + +}