epd2in9_V2.ino 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**
  2. * @filename : epd2in9_V2-demo.ino
  3. * @brief : 2.9inch e-paper V2 display demo
  4. * @author : Yehui from Waveshare
  5. *
  6. * Copyright (C) Waveshare Nov 09 2020
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documnetation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include <SPI.h>
  27. #include "epd2in9_V2.h"
  28. #include "epdpaint.h"
  29. #include "imagedata.h"
  30. #define COLORED 0
  31. #define UNCOLORED 1
  32. /**
  33. * Due to RAM not enough in Arduino UNO, a frame buffer is not allowed.
  34. * In this case, a smaller image buffer is allocated and you have to
  35. * update a partial display several times.
  36. * 1 byte = 8 pixels, therefore you have to set 8*N pixels at a time.
  37. */
  38. unsigned char image[1024];
  39. Paint paint(image, 0, 0); // width should be the multiple of 8
  40. Epd epd;
  41. unsigned long time_start_ms;
  42. unsigned long time_now_s;
  43. char time_string[] = {'0', '0', ':', '0', '0', '\0'};
  44. void setup() {
  45. // put your setup code here, to run once:
  46. Serial.begin(115200);
  47. if (epd.Init() != 0) {
  48. Serial.print("e-Paper init failed");
  49. return;
  50. }
  51. #if 1
  52. epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
  53. epd.DisplayFrame();
  54. paint.SetRotate(ROTATE_0);
  55. paint.SetWidth(128);
  56. paint.SetHeight(24);
  57. /* For simplicity, the arguments are explicit numerical coordinates */
  58. paint.Clear(COLORED);
  59. paint.DrawStringAt(0, 4, "Hello world!", &Font12, UNCOLORED);
  60. epd.SetFrameMemory(paint.GetImage(), 0, 10, paint.GetWidth(), paint.GetHeight());
  61. paint.Clear(UNCOLORED);
  62. paint.DrawStringAt(0, 4, "e-Paper Demo", &Font12, COLORED);
  63. epd.SetFrameMemory(paint.GetImage(), 0, 30, paint.GetWidth(), paint.GetHeight());
  64. paint.SetWidth(64);
  65. paint.SetHeight(64);
  66. paint.Clear(UNCOLORED);
  67. paint.DrawRectangle(0, 0, 40, 50, COLORED);
  68. paint.DrawLine(0, 0, 40, 50, COLORED);
  69. paint.DrawLine(40, 0, 0, 50, COLORED);
  70. epd.SetFrameMemory(paint.GetImage(), 8, 60, paint.GetWidth(), paint.GetHeight());
  71. paint.Clear(UNCOLORED);
  72. paint.DrawCircle(32, 32, 30, COLORED);
  73. epd.SetFrameMemory(paint.GetImage(), 56, 60, paint.GetWidth(), paint.GetHeight());
  74. paint.Clear(UNCOLORED);
  75. paint.DrawFilledRectangle(0, 0, 40, 50, COLORED);
  76. epd.SetFrameMemory(paint.GetImage(), 8, 130, paint.GetWidth(), paint.GetHeight());
  77. paint.Clear(UNCOLORED);
  78. paint.DrawFilledCircle(32, 32, 30, COLORED);
  79. epd.SetFrameMemory(paint.GetImage(), 56, 130, paint.GetWidth(), paint.GetHeight());
  80. epd.DisplayFrame();
  81. delay(2000);
  82. #endif
  83. #if 1
  84. if (epd.Init() != 0) {
  85. Serial.print("e-Paper init failed ");
  86. return;
  87. }
  88. /**
  89. * there are 2 memory areas embedded in the e-paper display
  90. * and once the display is refreshed, the memory area will be auto-toggled,
  91. * i.e. the next action of SetFrameMemory will set the other memory area
  92. * therefore you have to set the frame memory and refresh the display twice.
  93. */
  94. epd.SetFrameMemory_Base(IMAGE_DATA);
  95. epd.DisplayFrame();
  96. #endif
  97. #if 0
  98. // Quick brush demo
  99. if (epd.Init_Fast() != 0) {
  100. Serial.print("e-Paper init failed ");
  101. return;
  102. }
  103. /**
  104. * there are 2 memory areas embedded in the e-paper display
  105. * and once the display is refreshed, the memory area will be auto-toggled,
  106. * i.e. the next action of SetFrameMemory will set the other memory area
  107. * therefore you have to set the frame memory and refresh the display twice.
  108. */
  109. epd.SetFrameMemory_Base(IMAGE_DATA);
  110. epd.DisplayFrame();
  111. #endif
  112. #if 0
  113. Serial.print("show 4-gray image\r\n");
  114. if (epd.Init_4Gray() != 0) {
  115. Serial.print("e-Paper init failed ");
  116. return;
  117. }
  118. epd.Display4Gray(IMAGE_DATA_4Gray);
  119. #endif
  120. #if 0
  121. if (epd.Init() != 0) {
  122. Serial.print("e-Paper init failed");
  123. return;
  124. }
  125. epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
  126. epd.DisplayFrame();
  127. time_start_ms = millis();
  128. // put your main code here, to run repeatedly:
  129. for(;;){
  130. time_now_s = (millis() - time_start_ms) / 1000;
  131. time_string[0] = time_now_s / 60 / 10 + '0';
  132. time_string[1] = time_now_s / 60 % 10 + '0';
  133. time_string[3] = time_now_s % 60 / 10 + '0';
  134. time_string[4] = time_now_s % 60 % 10 + '0';
  135. paint.SetWidth(32);
  136. paint.SetHeight(96);
  137. paint.SetRotate(ROTATE_90);
  138. paint.Clear(UNCOLORED);
  139. paint.DrawStringAt(0, 4, time_string, &Font24, COLORED);
  140. epd.SetFrameMemory_Partial(paint.GetImage(), 80, 72, paint.GetWidth(), paint.GetHeight());
  141. epd.DisplayFrame_Partial();
  142. }
  143. #endif
  144. /* Deep sleep */
  145. Serial.print("sleep...");
  146. epd.Sleep();
  147. }
  148. void loop() {
  149. // delay(300);
  150. }