OLED_2in42.ino 2.7 KB

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