matrix8x8.ino 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /***************************************************
  2. This is a library for our I2C LED Backpacks
  3. Designed specifically to work with the Adafruit LED Matrix backpacks
  4. ----> http://www.adafruit.com/products/872
  5. ----> http://www.adafruit.com/products/871
  6. ----> http://www.adafruit.com/products/870
  7. These displays use I2C to communicate, 2 pins are required to
  8. interface. There are multiple selectable I2C addresses. For backpacks
  9. with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
  10. with 3 Address Select pins: 0x70 thru 0x77
  11. Adafruit invests time and resources providing this open source code,
  12. please support Adafruit and open-source hardware by purchasing
  13. products from Adafruit!
  14. Written by Limor Fried/Ladyada for Adafruit Industries.
  15. BSD license, all text above must be included in any redistribution
  16. ****************************************************/
  17. #include <Wire.h>
  18. #include <Adafruit_GFX.h>
  19. #include "Adafruit_LEDBackpack.h"
  20. Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
  21. void setup() {
  22. Serial.begin(9600);
  23. Serial.println("8x8 LED Matrix Test");
  24. matrix.begin(0x70); // pass in the address
  25. }
  26. static const uint8_t PROGMEM
  27. smile_bmp[] =
  28. { B00111100,
  29. B01000010,
  30. B10100101,
  31. B10000001,
  32. B10100101,
  33. B10011001,
  34. B01000010,
  35. B00111100 },
  36. neutral_bmp[] =
  37. { B00111100,
  38. B01000010,
  39. B10100101,
  40. B10000001,
  41. B10111101,
  42. B10000001,
  43. B01000010,
  44. B00111100 },
  45. frown_bmp[] =
  46. { B00111100,
  47. B01000010,
  48. B10100101,
  49. B10000001,
  50. B10011001,
  51. B10100101,
  52. B01000010,
  53. B00111100 };
  54. void loop() {
  55. matrix.clear();
  56. matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
  57. matrix.writeDisplay();
  58. delay(500);
  59. matrix.clear();
  60. matrix.drawBitmap(0, 0, neutral_bmp, 8, 8, LED_ON);
  61. matrix.writeDisplay();
  62. delay(500);
  63. matrix.clear();
  64. matrix.drawBitmap(0, 0, frown_bmp, 8, 8, LED_ON);
  65. matrix.writeDisplay();
  66. delay(500);
  67. matrix.clear(); // clear display
  68. matrix.drawPixel(0, 0, LED_ON);
  69. matrix.writeDisplay(); // write the changes we just made to the display
  70. delay(500);
  71. matrix.clear();
  72. matrix.drawLine(0,0, 7,7, LED_ON);
  73. matrix.writeDisplay(); // write the changes we just made to the display
  74. delay(500);
  75. matrix.clear();
  76. matrix.drawRect(0,0, 8,8, LED_ON);
  77. matrix.fillRect(2,2, 4,4, LED_ON);
  78. matrix.writeDisplay(); // write the changes we just made to the display
  79. delay(500);
  80. matrix.clear();
  81. matrix.drawCircle(3,3, 3, LED_ON);
  82. matrix.writeDisplay(); // write the changes we just made to the display
  83. delay(500);
  84. matrix.setTextSize(1);
  85. matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
  86. matrix.setTextColor(LED_ON);
  87. for (int8_t x=0; x>=-36; x--) {
  88. matrix.clear();
  89. matrix.setCursor(x,0);
  90. matrix.print("Hello");
  91. matrix.writeDisplay();
  92. delay(100);
  93. }
  94. matrix.setRotation(3);
  95. for (int8_t x=7; x>=-36; x--) {
  96. matrix.clear();
  97. matrix.setCursor(x,0);
  98. matrix.print("World");
  99. matrix.writeDisplay();
  100. delay(100);
  101. }
  102. matrix.setRotation(0);
  103. }