epd2in9bc.ino 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <SPI.h>
  2. #include "epd2in9b.h"
  3. #include "imagedata.h"
  4. #include "epdpaint.h"
  5. #define COLORED 0
  6. #define UNCOLORED 1
  7. void setup() {
  8. // put your setup code here, to run once:
  9. Serial.begin(9600);
  10. Epd epd;
  11. if (epd.Init() != 0) {
  12. Serial.print("e-Paper init failed");
  13. return;
  14. }
  15. /* This clears the SRAM of the e-paper display */
  16. epd.ClearFrame();
  17. /**
  18. * Due to RAM not enough in Arduino UNO, a frame buffer is not allowed.
  19. * In this case, a smaller image buffer is allocated and you have to
  20. * update a partial display several times.
  21. * 1 byte = 8 pixels, therefore you have to set 8*N pixels at a time.
  22. */
  23. unsigned char image[1024];
  24. Paint paint(image, 128, 18); //width should be the multiple of 8
  25. paint.Clear(UNCOLORED);
  26. paint.DrawStringAt(0, 0, "e-Paper Demo", &Font12, COLORED);
  27. epd.SetPartialWindowBlack(paint.GetImage(), 24, 32, paint.GetWidth(), paint.GetHeight());
  28. paint.Clear(COLORED);
  29. paint.DrawStringAt(2, 2, "Hello world", &Font16, UNCOLORED);
  30. epd.SetPartialWindowRed(paint.GetImage(), 0, 64, paint.GetWidth(), paint.GetHeight());
  31. paint.SetWidth(64);
  32. paint.SetHeight(64);
  33. paint.Clear(UNCOLORED);
  34. paint.DrawRectangle(0, 0, 40, 50, COLORED);
  35. paint.DrawLine(0, 0, 40, 50, COLORED);
  36. paint.DrawLine(40, 0, 0, 50, COLORED);
  37. epd.SetPartialWindowBlack(paint.GetImage(), 8, 120, paint.GetWidth(), paint.GetHeight());
  38. paint.Clear(UNCOLORED);
  39. paint.DrawCircle(32, 32, 30, COLORED);
  40. epd.SetPartialWindowBlack(paint.GetImage(), 64, 120, paint.GetWidth(), paint.GetHeight());
  41. paint.Clear(UNCOLORED);
  42. paint.DrawFilledRectangle(0, 0, 40, 50, COLORED);
  43. epd.SetPartialWindowRed(paint.GetImage(), 8, 200, paint.GetWidth(), paint.GetHeight());
  44. paint.Clear(UNCOLORED);
  45. paint.DrawFilledCircle(32, 32, 30, COLORED);
  46. epd.SetPartialWindowRed(paint.GetImage(), 64, 200, paint.GetWidth(), paint.GetHeight());
  47. /* This displays the data from the SRAM in e-Paper module */
  48. epd.DisplayFrame();
  49. /* This displays an image */
  50. epd.DisplayFrame(IMAGE_BLACK, IMAGE_RED);
  51. /* Deep sleep */
  52. epd.Sleep();
  53. }
  54. void loop() {
  55. // put your main code here, to run repeatedly:
  56. }