epd2in7b_V2.ino 3.2 KB

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