OLED_1in32.ino 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "OLED_Driver.h"
  2. #include "GUI_paint.h"
  3. #include "DEV_Config.h"
  4. #include "Debug.h"
  5. #include "ImageData.h"
  6. void setup() {
  7. System_Init();
  8. Serial.print(F("OLED_Init()...\r\n"));
  9. OLED_1in32_Init();
  10. Driver_Delay_ms(500);
  11. OLED_1in32_Clear(0);
  12. //0.Create a new image cache
  13. UBYTE *BlackImage;
  14. UWORD Imagesize = ((OLED_1in32_WIDTH%2==0)? (OLED_1in32_WIDTH/2): (OLED_1in32_WIDTH/2+1)) * OLED_1in32_HEIGHT;
  15. if((BlackImage = (UBYTE *)malloc(Imagesize/8)) == NULL) { //No enough memory
  16. Serial.print("Failed to apply for black memory...\r\n");
  17. return -1;
  18. }
  19. Serial.print("Paint_NewImage\r\n");
  20. Paint_NewImage(BlackImage, OLED_1in32_WIDTH/4, OLED_1in32_HEIGHT/2, 270, BLACK); // 32*48
  21. Paint_SetScale(16);
  22. //1.Select Image
  23. Paint_SelectImage(BlackImage);
  24. Paint_Clear(BLACK);
  25. Driver_Delay_ms(500);
  26. while(1) {
  27. Paint_SetRotate(0);
  28. // 2.Drawing on the image
  29. Serial.print("Drawing:page 1\r\n");
  30. Paint_DrawPoint(10, 10, WHITE, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  31. Paint_DrawPoint(10, 20, WHITE, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  32. Paint_DrawPoint(10, 30, WHITE, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  33. OLED_1in32_Display_Part(BlackImage, 0, 0, 32, 48);
  34. Paint_Clear(BLACK);
  35. Paint_DrawLine(10, 10, 25, 10, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  36. Paint_DrawLine(10, 20, 25, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  37. Paint_DrawLine(10, 30, 25, 30, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  38. Paint_DrawLine(10, 40, 25, 40, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  39. OLED_1in32_Display_Part(BlackImage, 0, 48, 32, 96);
  40. Paint_Clear(BLACK);
  41. Paint_DrawCircle(16, 16, 14, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  42. Paint_DrawRectangle(8, 8, 24, 24, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  43. OLED_1in32_Display_Part(BlackImage, 32, 0, 64, 48);
  44. Paint_Clear(BLACK);
  45. Paint_DrawCircle(16, 16, 14, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  46. Paint_DrawRectangle(8, 8, 24, 24, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  47. OLED_1in32_Display_Part(BlackImage, 32, 48, 64, 96);
  48. Paint_Clear(BLACK);
  49. OLED_1in32_Display_Part(BlackImage, 64, 0, 96, 48);
  50. OLED_1in32_Display_Part(BlackImage, 96, 0, 128, 48);
  51. OLED_1in32_Display_Part(BlackImage, 64, 48, 96, 96);
  52. OLED_1in32_Display_Part(BlackImage, 96, 48, 128, 96);
  53. Driver_Delay_ms(2000);
  54. Paint_Clear(BLACK);
  55. Paint_SetRotate(270);
  56. // Drawing on the image
  57. Serial.print("Drawing:page 2\r\n");
  58. for(UBYTE i=0; i<16; i++){
  59. Paint_DrawRectangle(0, 8*(i%4)+1, 47, 8*(i%4+1), i, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  60. if(i%4==3) {
  61. OLED_1in32_Display_Part(BlackImage, 32*(i/4), 0, 32*(i/4+1), 48);
  62. OLED_1in32_Display_Part(BlackImage, 32*(i/4), 48, 32*(i/4+1), 96);
  63. Paint_Clear(BLACK);
  64. }
  65. }
  66. Driver_Delay_ms(2000);
  67. // Drawing on the image
  68. Serial.print("Drawing:page 3\r\n");
  69. Paint_DrawString_EN(20, 10, "wave", &Font12, WHITE, WHITE);
  70. OLED_1in32_Display_Part(BlackImage, 0, 48, 32, 96);
  71. Paint_Clear(BLACK);
  72. Paint_DrawString_EN(0, 10, "share", &Font12, WHITE, WHITE);
  73. OLED_1in32_Display_Part(BlackImage, 0, 0, 32, 48);
  74. Paint_Clear(BLACK);
  75. Paint_DrawNum(2, 10, "12.3", &Font12, 2, WHITE, WHITE);
  76. OLED_1in32_Display_Part(BlackImage, 32, 0, 64, 48);
  77. Paint_Clear(BLACK);
  78. Paint_DrawNum(2, 10, "0.220", &Font12, 2, WHITE, WHITE);
  79. OLED_1in32_Display_Part(BlackImage, 32, 48, 64, 96);
  80. Paint_Clear(BLACK);
  81. Paint_DrawString_CN(2, 10,"你好", &Font12CN, WHITE, WHITE);
  82. OLED_1in32_Display_Part(BlackImage, 64, 0, 96, 48);
  83. Paint_Clear(BLACK);
  84. Paint_DrawString_CN(2, 10,"Abc", &Font12CN, WHITE, WHITE);
  85. OLED_1in32_Display_Part(BlackImage, 96, 0, 128, 48);
  86. Paint_Clear(BLACK);
  87. Driver_Delay_ms(2000);
  88. // show the array image
  89. Serial.print("Drawing:page 4\r\n");
  90. OLED_1in32_Display(gImage_1in32);
  91. Driver_Delay_ms(2000);
  92. Paint_Clear(BLACK);
  93. }
  94. }
  95. void loop() {
  96. }