Arduino_R4.ino 4.7 KB

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