2
0

epd4in2_V2.ino 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @filename : epd4in2_V2-demo.ino
  3. * @brief : 4.2inch e-paper V2 display demo
  4. * @author : Yehui from Waveshare
  5. *
  6. * Copyright (C) Waveshare August 4 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 "epd4in2_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(9600);
  35. Epd epd;
  36. if (epd.Init() != 0) {
  37. Serial.print("e-Paper init failed");
  38. return;
  39. }
  40. //Serial.print(UNCOLORED);
  41. /* This clears the SRAM of the e-paper display */
  42. epd.Clear();
  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[1500];
  51. Paint paint(image, 400, 28); //width should be the multiple of 8
  52. paint.Clear(UNCOLORED);
  53. paint.DrawStringAt(20, 5, "e-Paper Demo", &Font16, COLORED);
  54. epd.Display_Partial_Not_refresh(paint.GetImage(), 0, 32, 0+paint.GetWidth(), 32+paint.GetHeight());
  55. paint.Clear(COLORED);
  56. paint.DrawStringAt(20, 5, "Hello world!", &Font16, UNCOLORED);
  57. epd.Display_Partial_Not_refresh(paint.GetImage(), 0, 64, 0+paint.GetWidth(), 64+paint.GetHeight());
  58. paint.SetWidth(64);
  59. paint.SetHeight(64);
  60. paint.Clear(UNCOLORED);
  61. paint.DrawRectangle(0, 0, 40, 50, COLORED);
  62. paint.DrawLine(0, 0, 40, 50, COLORED);
  63. paint.DrawLine(40, 0, 0, 50, COLORED);
  64. epd.Display_Partial_Not_refresh(paint.GetImage(), 10, 130, 10+paint.GetWidth(), 130+paint.GetHeight());
  65. paint.Clear(UNCOLORED);
  66. paint.DrawCircle(32, 32, 30, COLORED);
  67. epd.Display_Partial_Not_refresh(paint.GetImage(), 90, 120, 90+paint.GetWidth(), 120+paint.GetHeight());
  68. paint.Clear(UNCOLORED);
  69. paint.DrawFilledRectangle(0, 0, 40, 50, COLORED);
  70. epd.Display_Partial_Not_refresh(paint.GetImage(), 10, 200, 10+paint.GetWidth(), 200+paint.GetHeight());
  71. paint.Clear(UNCOLORED);
  72. paint.DrawFilledCircle(32, 32, 30, COLORED);
  73. epd.Display_Partial(paint.GetImage(), 90, 190, 90+paint.GetWidth(), 190+paint.GetHeight());
  74. /* This displays an image */
  75. epd.Init();
  76. Serial.print("show 2-gray image\r\n");
  77. epd.Display(IMAGE_BUTTERFLY);
  78. delay(1000);
  79. #else
  80. Serial.print("show 4-gray image\r\n");
  81. epd.Init_4Gray();
  82. epd.Set_4GrayDisplay(gImage_4in2_4Gray1, 100, 100, 200, 150);
  83. #endif
  84. /* Deep sleep */
  85. epd.Sleep();
  86. }
  87. void loop() {
  88. // put your main code here, to run repeatedly:
  89. }