QRCode_halfsize.ino 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * QRCode
  3. *
  4. * A quick example of generating a QR code.
  5. *
  6. * This prints the QR code to the serial monitor as solid blocks. Each character
  7. * contains two blocks, since the monospace font used in the serial monitor
  8. * is approximately twice as tall as wide.
  9. *
  10. */
  11. #include "qrcode.h"
  12. void setup() {
  13. Serial.begin(115200);
  14. // Start time
  15. uint32_t dt = millis();
  16. // Create the QR code
  17. QRCode qrcode;
  18. uint8_t qrcodeData[qrcode_getBufferSize(3)];
  19. qrcode_initText(&qrcode, qrcodeData, 3, 0, "HELLO WORLD");
  20. // Delta time
  21. dt = millis() - dt;
  22. Serial.print("QR Code Generation Time: ");
  23. Serial.print(dt);
  24. Serial.print("\n");
  25. // Top quiet zone
  26. Serial.print("\n\n\n\n");
  27. for (uint8_t y = 0; y < qrcode.size; y += 2) {
  28. // Left quiet zone
  29. Serial.print(" ");
  30. // Each horizontal module
  31. for (uint8_t x = 0; x < qrcode.size; x++) {
  32. uint8_t block = qrcode_getModule(&qrcode, x, y) << 1 | qrcode_getModule(&qrcode, x, y + 1);
  33. switch (block)
  34. {
  35. case 0b00:
  36. Serial.print(" ");
  37. break;
  38. case 0b01:
  39. Serial.print("\u2584"); // \u2584 lower block
  40. break;
  41. case 0b10:
  42. Serial.print("\u2580"); // \u2580 upper block
  43. break;
  44. case 0b11:
  45. Serial.print("\u2588"); // \u2588 both blocks
  46. break;
  47. }
  48. }
  49. Serial.print("\n");
  50. }
  51. // Bottom quiet zone
  52. Serial.print("\n\n\n\n");
  53. }
  54. void loop() {
  55. }