matrix16x8.ino 3.5 KB

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