epd4in2b_V2.ino 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @filename : epd4in2b_V2.ino
  3. * @brief : 4.2inch e-paper display (B_V2) demo
  4. * @author : Yehui from Waveshare
  5. *
  6. * Copyright (C) Waveshare Nov 25 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 "epd4in2b_V2.h"
  28. #include "imagedata.h"
  29. #include "epdpaint.h"
  30. #define COLORED 0
  31. #define UNCOLORED 1
  32. void setup() {
  33. // put your setup code here, to run once:
  34. Serial.begin(115200);
  35. Epd epd;
  36. if (epd.Init() != 0) {
  37. Serial.print("e-Paper init failed");
  38. return;
  39. }
  40. /* This clears the SRAM of the e-paper display */
  41. epd.ClearFrame();
  42. /**
  43. * Due to RAM not enough in Arduino UNO, a frame buffer is not allowed.
  44. * In this case, a smaller image buffer is allocated and you have to
  45. * update a partial display several times.
  46. * 1 byte = 8 pixels, therefore you have to set 8*N pixels at a time.
  47. */
  48. unsigned char image[1500];
  49. Paint paint(image, 400, 28); //width should be the multiple of 8
  50. paint.Clear(UNCOLORED);
  51. paint.DrawStringAt(0, 0, "e-Paper Demo", &Font24, COLORED);
  52. epd.SetPartialWindowBlack(paint.GetImage(), 100, 40, paint.GetWidth(), paint.GetHeight());
  53. paint.Clear(COLORED);
  54. paint.DrawStringAt(100, 2, "Hello world", &Font24, UNCOLORED);
  55. epd.SetPartialWindowRed(paint.GetImage(), 0, 64, paint.GetWidth(), paint.GetHeight());
  56. paint.SetWidth(64);
  57. paint.SetHeight(64);
  58. paint.Clear(UNCOLORED);
  59. paint.DrawRectangle(0, 0, 40, 50, COLORED);
  60. paint.DrawLine(0, 0, 40, 50, COLORED);
  61. paint.DrawLine(40, 0, 0, 50, COLORED);
  62. epd.SetPartialWindowBlack(paint.GetImage(), 72, 120, paint.GetWidth(), paint.GetHeight());
  63. paint.Clear(UNCOLORED);
  64. paint.DrawCircle(32, 32, 30, COLORED);
  65. epd.SetPartialWindowBlack(paint.GetImage(), 200, 120, paint.GetWidth(), paint.GetHeight());
  66. paint.Clear(UNCOLORED);
  67. paint.DrawFilledRectangle(0, 0, 40, 50, COLORED);
  68. epd.SetPartialWindowRed(paint.GetImage(), 72, 200, paint.GetWidth(), paint.GetHeight());
  69. paint.Clear(UNCOLORED);
  70. paint.DrawFilledCircle(32, 32, 30, COLORED);
  71. epd.SetPartialWindowRed(paint.GetImage(), 200, 200, paint.GetWidth(), paint.GetHeight());
  72. /* This displays the data from the SRAM in e-Paper module */
  73. epd.DisplayFrame();
  74. delay(1000);
  75. /* This displays an image */
  76. // epd.DisplayFrame(IMAGE_BLACK, IMAGE_RED);
  77. /* Deep sleep */
  78. epd.ClearFrame();
  79. epd.DisplayFrame();
  80. epd.Sleep();
  81. }
  82. void loop() {
  83. // put your main code here, to run repeatedly:
  84. }