epd1in54.ino 4.9 KB

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