2
0

epd2in13.ino 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * @filename : epd2in13-demo.ino
  3. * @brief : 2.13inch e-paper display demo
  4. * @author : Yehui from Waveshare
  5. *
  6. * Copyright (C) Waveshare September 9 2017
  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 "epd2in13.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);
  40. Epd epd;
  41. unsigned long time_start_ms;
  42. unsigned long time_now_s;
  43. void setup() {
  44. // put your setup code here, to run once:
  45. Serial.begin(9600);
  46. if (epd.Init(lut_full_update) != 0) {
  47. Serial.print("e-Paper init failed");
  48. return;
  49. }
  50. epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
  51. paint.SetRotate(ROTATE_0);
  52. paint.SetWidth(128); // width should be the multiple of 8
  53. paint.SetHeight(24);
  54. /* For simplicity, the arguments are explicit numerical coordinates */
  55. paint.Clear(COLORED);
  56. paint.DrawStringAt(30, 4, "Hello world!", &Font12, UNCOLORED);
  57. epd.SetFrameMemory(paint.GetImage(), 0, 10, paint.GetWidth(), paint.GetHeight());
  58. paint.Clear(UNCOLORED);
  59. paint.DrawStringAt(30, 4, "e-Paper Demo", &Font12, COLORED);
  60. epd.SetFrameMemory(paint.GetImage(), 0, 30, paint.GetWidth(), paint.GetHeight());
  61. paint.SetWidth(64);
  62. paint.SetHeight(64);
  63. paint.Clear(UNCOLORED);
  64. paint.DrawRectangle(0, 0, 40, 50, COLORED);
  65. paint.DrawLine(0, 0, 40, 50, COLORED);
  66. paint.DrawLine(40, 0, 0, 50, COLORED);
  67. epd.SetFrameMemory(paint.GetImage(), 16, 60, paint.GetWidth(), paint.GetHeight());
  68. paint.Clear(UNCOLORED);
  69. paint.DrawCircle(32, 32, 30, COLORED);
  70. epd.SetFrameMemory(paint.GetImage(), 72, 60, paint.GetWidth(), paint.GetHeight());
  71. paint.Clear(UNCOLORED);
  72. paint.DrawFilledRectangle(0, 0, 40, 50, COLORED);
  73. epd.SetFrameMemory(paint.GetImage(), 16, 130, paint.GetWidth(), paint.GetHeight());
  74. paint.Clear(UNCOLORED);
  75. paint.DrawFilledCircle(32, 32, 30, COLORED);
  76. epd.SetFrameMemory(paint.GetImage(), 72, 130, paint.GetWidth(), paint.GetHeight());
  77. epd.DisplayFrame();
  78. delay(2000);
  79. if (epd.Init(lut_partial_update) != 0) {
  80. Serial.print("e-Paper init failed");
  81. return;
  82. }
  83. /**
  84. * there are 2 memory areas embedded in the e-paper display
  85. * and once the display is refreshed, the memory area will be auto-toggled,
  86. * i.e. the next action of SetFrameMemory will set the other memory area
  87. * therefore you have to set the frame memory and refresh the display twice.
  88. */
  89. epd.SetFrameMemory(IMAGE_DATA);
  90. epd.DisplayFrame();
  91. epd.SetFrameMemory(IMAGE_DATA);
  92. epd.DisplayFrame();
  93. time_start_ms = millis();
  94. }
  95. void loop() {
  96. // put your main code here, to run repeatedly:
  97. time_now_s = (millis() - time_start_ms) / 1000;
  98. char time_string[] = {'0', '0', ':', '0', '0', '\0'};
  99. time_string[0] = time_now_s / 60 / 10 + '0';
  100. time_string[1] = time_now_s / 60 % 10 + '0';
  101. time_string[3] = time_now_s % 60 / 10 + '0';
  102. time_string[4] = time_now_s % 60 % 10 + '0';
  103. paint.SetWidth(32);
  104. paint.SetHeight(96);
  105. paint.SetRotate(ROTATE_90);
  106. paint.Clear(UNCOLORED);
  107. paint.DrawStringAt(0, 4, time_string, &Font24, COLORED);
  108. epd.SetFrameMemory(paint.GetImage(), 80, 72, paint.GetWidth(), paint.GetHeight());
  109. epd.DisplayFrame();
  110. delay(500);
  111. }