epd2in9-demo.ino 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @filename : epd2in9-demo.ino
  3. * @brief : 2.9inch e-paper display demo
  4. * @author : Yehui from Waveshare
  5. *
  6. * Copyright (C) Waveshare September 9 2017
  7. *
  8. * @author : Updated by krzychb@gazeta,pl
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documnetation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. * THE SOFTWARE.
  27. */
  28. #include <SPI.h>
  29. #include <epd2in9.h>
  30. #include <epdpaint.h>
  31. #include "imagedata.h"
  32. #define COLORED 0
  33. #define UNCOLORED 1
  34. unsigned char image[4736];
  35. Paint paint(image, 0, 0); // width should be the multiple of 8
  36. Epd epd;
  37. void setup() {
  38. Serial.begin(115200);
  39. Serial.println("Starting...");
  40. if (epd.Init(lut_full_update) != 0) {
  41. Serial.println("e-Paper init failed");
  42. return;
  43. }
  44. Serial.println("Init done");
  45. }
  46. void loop() {
  47. // Clear image memory
  48. epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
  49. epd.DisplayFrame();
  50. Serial.println("Cleared frame memory");
  51. // Welcome text
  52. paint.SetRotate(ROTATE_270);
  53. paint.SetWidth(128);
  54. paint.SetHeight(296);
  55. paint.Clear(UNCOLORED);
  56. paint.DrawStringAt(50, 50, "Hello world!", &Font24, COLORED);
  57. epd.SetFrameMemory(paint.GetImage(), 0, 0, paint.GetWidth(), paint.GetHeight());
  58. epd.DisplayFrame();
  59. Serial.println("Displayed welcome text");
  60. delay(3000);
  61. epd.SetFrameMemory(IMAGE_DATA);
  62. epd.DisplayFrame();
  63. Serial.println("Displayed image data");
  64. delay(3000);
  65. // Black screen
  66. epd.ClearFrameMemory(0);
  67. epd.DisplayFrame();
  68. Serial.println("Displayed black screen");
  69. delay(3000);
  70. epd.Reset();
  71. }