display_frame_renderer.ino 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Use the MD_MAX72XX library to Print some text on the display
  2. //
  3. // Demonstrates the use of the library to print text.
  4. //
  5. // User can enter text on the serial monitor and this will display as a
  6. // message on the display.
  7. // Library doc https://majicdesigns.github.io/MD_MAX72XX/class_m_d___m_a_x72_x_x.html
  8. #include <MD_MAX72xx.h>
  9. #include <SPI.h>
  10. #define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }
  11. // Define the number of devices we have in the chain and the hardware interface
  12. // NOTE: These pin numbers will probably not work with your hardware and may
  13. // need to be adapted
  14. #define HARDWARE_TYPE MD_MAX72XX::DR1CR0RR0_HW
  15. #define MAX_DEVICES 8
  16. #define CLK_PIN 32 // or SCK
  17. #define DATA_PIN 33 // or MOSI
  18. #define CS_PIN 25 // or SS
  19. // 'test-frame', 32x16px
  20. const unsigned char epd_bitmap_test_frame [] PROGMEM = {
  21. 0x00, 0x00, 0x00, 0x00,
  22. 0x00, 0x00, 0x00, 0x00,
  23. 0x00, 0x00, 0x00, 0x00,
  24. 0x22, 0x00, 0x00, 0x44,
  25. 0x44, 0x00, 0x00, 0x22,
  26. 0x89, 0x80, 0x01, 0x91,
  27. 0x92, 0x40, 0x02, 0x49,
  28. 0x82, 0x40, 0x02, 0x41,
  29. 0x81, 0x80, 0x01, 0x81,
  30. 0x80, 0x04, 0x40, 0x01,
  31. 0x80, 0x09, 0x20, 0x01,
  32. 0x87, 0x89, 0x21, 0xe1,
  33. 0x40, 0x06, 0xc0, 0x02,
  34. 0x27, 0x80, 0x01, 0xe4,
  35. 0x00, 0x00, 0x00, 0x00,
  36. 0x00, 0x00, 0x00, 0x00
  37. };
  38. // Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 80)
  39. const int epd_bitmap_allArray_LEN = 1;
  40. const unsigned char* epd_bitmap_allArray[1] = {
  41. epd_bitmap_test_frame
  42. };
  43. // SPI hardware interface
  44. //MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
  45. // Arbitrary pins
  46. MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
  47. byte fByte(byte c){ char r=0; for(byte i = 0; i < 8; i++){ r <<= 1; r |= c & 1; c >>= 1; } return r;}
  48. void renderFrame(){
  49. //Top half of the display
  50. int fsize = sizeof(epd_bitmap_test_frame);
  51. for (int i = 0; i < fsize/2; i+=4) {
  52. for (int d=0; d<=3; d++){
  53. //For each of the driver, from 0 to 3
  54. byte rowData = pgm_read_byte(&epd_bitmap_test_frame[i + d]);
  55. mx.setRow(d,d,7 - int(i/4),fByte(rowData));
  56. }
  57. }
  58. //Bottom half of the display
  59. for (int i = fsize/2; i < fsize; i+=4) {
  60. for (int d=4; d<=7; d++){
  61. //For each of the driver, from 4 to 7
  62. byte rowData = pgm_read_byte(&epd_bitmap_test_frame[i + (d - 4)]);
  63. mx.setRow(d,d,7 - (int(i/4) - 8),fByte(rowData));
  64. }
  65. }
  66. }
  67. void setup(){
  68. mx.begin();
  69. Serial.begin(57600);
  70. Serial.print("\nFrame Rendering");
  71. renderFrame();
  72. Serial.print("\nDone");
  73. }
  74. void loop(){
  75. }