OLED_0in91.ino 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. if(USE_SPI_4W) {
  9. Serial.print("Only USE_IIC, Please revise DEV_Config.h !!!\r\n");
  10. return -1;
  11. }
  12. Serial.print(F("OLED_Init()...\r\n"));
  13. OLED_0in91_Init();
  14. Driver_Delay_ms(500);
  15. OLED_0in91_Clear();
  16. //0.Create a new image cache
  17. UBYTE *BlackImage;
  18. UWORD Imagesize = ((OLED_0in91_WIDTH%8==0)? (OLED_0in91_WIDTH/8): (OLED_0in91_WIDTH/8+1)) * OLED_0in91_HEIGHT;
  19. if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
  20. Serial.print("Failed to apply for black memory...\r\n");
  21. return -1;
  22. }
  23. Serial.print("Paint_NewImage\r\n");
  24. Paint_NewImage(BlackImage, OLED_0in91_HEIGHT, OLED_0in91_WIDTH, 90, BLACK);
  25. //1.Select Image
  26. Paint_SelectImage(BlackImage);
  27. Paint_Clear(BLACK);
  28. Driver_Delay_ms(500);
  29. while(1) {
  30. // 2.Drawing on the image
  31. Serial.print("Drawing:page 1\r\n");
  32. Paint_DrawPoint(15, 10, WHITE, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  33. Paint_DrawPoint(25, 10, WHITE, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  34. Paint_DrawPoint(35, 10, WHITE, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  35. Paint_DrawLine(10, 10, 10, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  36. Paint_DrawLine(20, 10, 20, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  37. Paint_DrawLine(30, 10, 30, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  38. Paint_DrawLine(40, 10, 40, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  39. Paint_DrawCircle(70, 16, 15, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  40. Paint_DrawCircle(110, 16, 15, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  41. Paint_DrawRectangle(60, 6, 80, 26, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  42. Paint_DrawRectangle(100, 6, 120, 26, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  43. // 3.Show image on page1
  44. OLED_0in91_Display(BlackImage);
  45. Driver_Delay_ms(2000);
  46. Paint_Clear(BLACK);
  47. // Drawing on the image
  48. Serial.print("Drawing:page 2\r\n");
  49. Paint_DrawString_EN(10, 0, "waveshare", &Font16, WHITE, WHITE);
  50. Paint_DrawNum(10, 18, "123.456789", &Font12, 4, WHITE, WHITE);
  51. // Show image on page2
  52. OLED_0in91_Display(BlackImage);
  53. Driver_Delay_ms(2000);
  54. Paint_Clear(BLACK);
  55. // Drawing on the image
  56. Serial.print("Drawing:page 3\r\n");
  57. Paint_DrawString_CN(0, 0,"你好Aba", &Font12CN, WHITE, WHITE);
  58. // Show image on page3
  59. OLED_0in91_Display(BlackImage);
  60. Driver_Delay_ms(2000);
  61. Paint_Clear(BLACK);
  62. // Drawing on the image
  63. Serial.print("Drawing:page 4\r\n");
  64. OLED_0in91_Display_Array(gImage_0in91);
  65. Driver_Delay_ms(2000);
  66. Paint_Clear(BLACK);
  67. OLED_0in91_Clear();
  68. }
  69. }
  70. void loop() {
  71. }