OLED_0in96.ino 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_0in96_Init();
  10. Driver_Delay_ms(500);
  11. OLED_0in96_clear();
  12. //0.Create a new image cache
  13. UBYTE *BlackImage;
  14. UWORD Imagesize = ((OLED_0in96_WIDTH%8==0)? (OLED_0in96_WIDTH/8): (OLED_0in96_WIDTH/8+1)) * OLED_0in96_HEIGHT;
  15. if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
  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_0in96_WIDTH, OLED_0in96_HEIGHT, 90, BLACK);
  21. //1.Select Image
  22. Paint_SelectImage(BlackImage);
  23. Paint_Clear(BLACK);
  24. Driver_Delay_ms(500);
  25. while(1) {
  26. // 2.Drawing on the image
  27. Serial.print("Drawing:page 1\r\n");
  28. Paint_DrawPoint(20, 10, WHITE, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  29. Paint_DrawPoint(30, 10, WHITE, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  30. Paint_DrawPoint(40, 10, WHITE, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  31. Paint_DrawLine(10, 10, 10, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  32. Paint_DrawLine(20, 20, 20, 30, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  33. Paint_DrawLine(30, 30, 30, 40, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  34. Paint_DrawLine(40, 40, 40, 50, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  35. Paint_DrawCircle(60, 30, 15, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  36. Paint_DrawCircle(100, 40, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  37. Paint_DrawRectangle(50, 30, 60, 40, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  38. Paint_DrawRectangle(90, 30, 110, 50, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  39. // 3.Show image on page1
  40. OLED_0in96_display(BlackImage);
  41. Driver_Delay_ms(2000);
  42. Paint_Clear(BLACK);
  43. // Drawing on the image
  44. Serial.print("Drawing:page 2\r\n");
  45. Paint_DrawString_EN(10, 0, "waveshare", &Font16, WHITE, WHITE);
  46. Paint_DrawString_EN(10, 17, "hello world", &Font8, WHITE, WHITE);
  47. Paint_DrawNum(10, 30, "123.456789", &Font8, 4, WHITE, WHITE);
  48. Paint_DrawNum(10, 43, "987654", &Font12, 5, WHITE, WHITE);
  49. // Show image on page2
  50. OLED_0in96_display(BlackImage);
  51. Driver_Delay_ms(2000);
  52. Paint_Clear(BLACK);
  53. // Drawing on the image
  54. Serial.print("Drawing:page 3\r\n");
  55. Paint_DrawString_CN(10, 0,"你好Abc", &Font12CN, WHITE, WHITE);
  56. Paint_DrawString_CN(0, 20, "微雪电子", &Font24CN, WHITE, WHITE);
  57. // Show image on page3
  58. OLED_0in96_display(BlackImage);
  59. Driver_Delay_ms(2000);
  60. Paint_Clear(BLACK);
  61. // Drawing on the image
  62. Serial.print("Drawing:page 4\r\n");
  63. OLED_0in96_display_Array(gImage_0in96);
  64. Driver_Delay_ms(2000);
  65. Paint_Clear(BLACK);
  66. OLED_0in96_clear();
  67. }
  68. }
  69. void loop() {
  70. }