OLED_1in5.ino 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_1in5_Init();
  10. Driver_Delay_ms(500);
  11. OLED_1in5_Clear();
  12. //0.Create a new image cache
  13. UBYTE *BlackImage;
  14. UWORD Imagesize = ((OLED_1in5_WIDTH%2==0)? (OLED_1in5_WIDTH/2): (OLED_1in5_WIDTH/2+1)) * OLED_1in5_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_1in5_WIDTH/4, OLED_1in5_HEIGHT/2, 270, BLACK);
  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. // 2.Drawing on the image
  28. Serial.print("Drawing:page 1\r\n");
  29. Paint_DrawPoint(10, 10, WHITE, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  30. Paint_DrawPoint(25, 10, WHITE, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  31. Paint_DrawPoint(40, 10, WHITE, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  32. OLED_1in5_Display_Part(BlackImage, 0, 0, 32, 64);
  33. Paint_Clear(BLACK);
  34. Paint_DrawLine(10, 10, 10, 25, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  35. Paint_DrawLine(20, 10, 20, 25, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  36. Paint_DrawLine(30, 10, 30, 25, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  37. Paint_DrawLine(40, 10, 40, 25, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  38. OLED_1in5_Display_Part(BlackImage, 32, 64, 64, 128);
  39. Paint_Clear(BLACK);
  40. Paint_DrawCircle(30, 16, 14, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  41. Paint_DrawRectangle(22, 8, 38, 24, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  42. OLED_1in5_Display_Part(BlackImage, 32, 0, 64, 64);
  43. Paint_Clear(BLACK);
  44. Paint_DrawCircle(30, 16, 14, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  45. Paint_DrawRectangle(22, 8, 38, 24, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  46. OLED_1in5_Display_Part(BlackImage, 0, 64, 32, 128);
  47. Driver_Delay_ms(2000);
  48. Paint_Clear(BLACK);
  49. // Drawing on the image
  50. Serial.print("Drawing:page 2\r\n");
  51. for(UBYTE i=0; i<16; i++){
  52. Paint_DrawRectangle(0, 8*(i%4)+1, 63, 8*(i%4+1), i, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  53. if(i%4==3) {
  54. OLED_1in5_Display_Part(BlackImage, 32*(i/4), 0, 32*(i/4+1), 64);
  55. Paint_Clear(BLACK);
  56. }
  57. }
  58. Driver_Delay_ms(2000);
  59. // Drawing on the image
  60. Serial.print("Drawing:page 3\r\n");
  61. Paint_DrawString_EN(10, 0, "waveshare", &Font16, WHITE, WHITE);
  62. OLED_1in5_Display_Part(BlackImage, 0, 0, 32, 64);
  63. Paint_Clear(BLACK);
  64. Paint_DrawNum(0, 10, "123.456", &Font12, 2, WHITE, WHITE);
  65. OLED_1in5_Display_Part(BlackImage, 0, 64, 32, 128);
  66. Driver_Delay_ms(2000);
  67. Paint_Clear(BLACK);
  68. Paint_DrawString_CN(0, 0,"你好Ab", &Font12CN, WHITE, WHITE);
  69. OLED_1in5_Display_Part(BlackImage, 32, 0, 64, 64);
  70. Driver_Delay_ms(2000);
  71. Paint_Clear(BLACK);
  72. // show the array image
  73. Serial.print("Drawing:page 4\r\n");
  74. OLED_1in5_Display(gImage_1in5);
  75. Driver_Delay_ms(2000);
  76. Paint_Clear(BLACK);
  77. OLED_1in5_Clear();
  78. }
  79. }
  80. void loop() {
  81. }