ESP32.ino 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "EPD_1in54g.h"
  2. #include "GUI_Paint.h"
  3. #include "fonts.h"
  4. #include "ImageData.h"
  5. void setup() {
  6. printf("EPD_2IN15G_test Demo\r\n");
  7. if(DEV_Module_Init()!=0){
  8. DEV_Module_Exit();
  9. while(1);
  10. }
  11. printf("e-Paper Init and Clear...\r\n");
  12. EPD_1IN54G_Init();
  13. EPD_1IN54G_Clear(EPD_1IN54G_WHITE); // White
  14. DEV_Delay_ms(2000);
  15. //Create a new image cache
  16. UBYTE *BlackImage;
  17. UWORD Imagesize = ((EPD_1IN54G_WIDTH % 4 == 0)? (EPD_1IN54G_WIDTH / 4 ): (EPD_1IN54G_WIDTH / 4 + 1)) * EPD_1IN54G_HEIGHT;
  18. if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
  19. printf("Failed to apply for black memory...\r\n");
  20. while(1);
  21. }
  22. printf("Paint_NewImage\r\n");
  23. Paint_NewImage(BlackImage, EPD_1IN54G_WIDTH, EPD_1IN54G_HEIGHT, 90, EPD_1IN54G_WHITE);
  24. Paint_SetScale(4);
  25. #if 1 // show bmp
  26. printf("show BMP-----------------\r\n");
  27. EPD_1IN54G_Display(Image4color);
  28. DEV_Delay_ms(2000);
  29. #endif
  30. #if 1 // Drawing on the image
  31. //1.Select Image
  32. EPD_1IN54G_Init_Fast();
  33. printf("SelectImage:BlackImage\r\n");
  34. Paint_NewImage(BlackImage, EPD_1IN54G_WIDTH, EPD_1IN54G_HEIGHT, 90, EPD_1IN54G_WHITE);
  35. Paint_SetScale(4);
  36. Paint_SelectImage(BlackImage);
  37. Paint_Clear(EPD_1IN54G_WHITE);
  38. // 2.Drawing on the image
  39. printf("Drawing:BlackImage\r\n");
  40. Paint_DrawPoint(10, 80, EPD_1IN54G_RED, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  41. Paint_DrawPoint(10, 90, EPD_1IN54G_YELLOW, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  42. Paint_DrawPoint(10, 100, EPD_1IN54G_BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  43. Paint_DrawLine(20, 70, 70, 120, EPD_1IN54G_RED, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  44. Paint_DrawLine(70, 70, 20, 120, EPD_1IN54G_RED, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  45. Paint_DrawRectangle(20, 70, 70, 120, EPD_1IN54G_YELLOW, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  46. Paint_DrawRectangle(80, 70, 130, 120, EPD_1IN54G_YELLOW, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  47. Paint_DrawCircle(45, 95, 20, EPD_1IN54G_BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  48. Paint_DrawCircle(105, 95, 20, EPD_1IN54G_BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  49. Paint_DrawLine(85, 95, 125, 95, EPD_1IN54G_RED, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  50. Paint_DrawLine(105, 75, 105, 115, EPD_1IN54G_YELLOW, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  51. Paint_DrawString_EN(10, 0, "Red,yellow,", &Font16, EPD_1IN54G_RED, EPD_1IN54G_YELLOW);
  52. Paint_DrawString_EN(10, 20, "white and black", &Font16, EPD_1IN54G_RED, EPD_1IN54G_YELLOW);
  53. Paint_DrawString_EN(10, 40, "Four color e-Paper", &Font12, EPD_1IN54G_YELLOW, EPD_1IN54G_BLACK);
  54. Paint_DrawString_CN(10, 150, "微雪电子", &Font24CN, EPD_1IN54G_RED, EPD_1IN54G_WHITE);
  55. Paint_DrawNum(10, 135, 123456, &Font12, EPD_1IN54G_RED, EPD_1IN54G_WHITE);
  56. printf("EPD_Display\r\n");
  57. EPD_1IN54G_Display(BlackImage);
  58. DEV_Delay_ms(3000);
  59. #endif
  60. Paint_NewImage(BlackImage, EPD_1IN54G_WIDTH, EPD_1IN54G_HEIGHT, 0, EPD_1IN54G_WHITE);
  61. Paint_SetScale(4);
  62. #if 1 // Drawing on the image
  63. //1.Select Image
  64. printf("SelectImage:BlackImage\r\n");
  65. Paint_SelectImage(BlackImage);
  66. Paint_Clear(EPD_1IN54G_WHITE);
  67. // 2.Drawing on the image
  68. printf("Drawing:BlackImage\r\n");
  69. Paint_DrawRectangle(1, 1, EPD_1IN54G_WIDTH, EPD_1IN54G_HEIGHT/4, EPD_1IN54G_RED, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  70. Paint_DrawRectangle(1, EPD_1IN54G_HEIGHT/4, EPD_1IN54G_WIDTH, EPD_1IN54G_HEIGHT/2, EPD_1IN54G_YELLOW, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  71. Paint_DrawRectangle(1, EPD_1IN54G_HEIGHT/2, EPD_1IN54G_WIDTH, EPD_1IN54G_HEIGHT/4*3, EPD_1IN54G_BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  72. printf("EPD_Display\r\n");
  73. EPD_1IN54G_Display(BlackImage);
  74. DEV_Delay_ms(3000);
  75. #endif
  76. #if 1 // Drawing on the image
  77. //1.Select Image
  78. printf("SelectImage:BlackImage\r\n");
  79. Paint_SelectImage(BlackImage);
  80. Paint_Clear(EPD_1IN54G_WHITE);
  81. int hNumber, hWidth, vNumber, vWidth;
  82. hNumber = 20;
  83. hWidth = EPD_1IN54G_HEIGHT/hNumber;
  84. vNumber = 8;
  85. vWidth = EPD_1IN54G_WIDTH/vNumber;
  86. // 2.Drawing on the image
  87. printf("Drawing:BlackImage\r\n");
  88. for(int i=0; i<hNumber; i++) { // horizontal
  89. Paint_DrawRectangle(1, 1+i*hWidth, EPD_1IN54G_WIDTH, hWidth*(1+i), EPD_1IN54G_BLACK + (i % 2), DOT_PIXEL_1X1, DRAW_FILL_FULL);
  90. }
  91. for(int i=0; i<vNumber; i++) { // vertical
  92. if(i%2) {
  93. Paint_DrawRectangle(1+i*vWidth, 1, vWidth*(i+1), EPD_1IN54G_HEIGHT, EPD_1IN54G_YELLOW + (i/2%2), DOT_PIXEL_1X1, DRAW_FILL_FULL);
  94. }
  95. }
  96. printf("EPD_Display\r\n");
  97. EPD_1IN54G_Display(BlackImage);
  98. DEV_Delay_ms(3000);
  99. #endif
  100. printf("Clear...\r\n");
  101. EPD_1IN54G_Init();
  102. EPD_1IN54G_Clear(EPD_1IN54G_WHITE);
  103. printf("Goto Sleep...\r\n");
  104. EPD_1IN54G_Sleep();
  105. free(BlackImage);
  106. BlackImage = NULL;
  107. DEV_Delay_ms(2000);//important, at least 2s
  108. // close 5V
  109. printf("close 5V, Module enters 0 power consumption ...\r\n");
  110. DEV_Module_Exit();
  111. }
  112. void loop() {
  113. }