epd2in13b_V4.ino 3.1 KB

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