drawXBitmap.ino 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Example sketch to demonstrate the drawing of X BitMap (XBM)
  2. // format image onto the display.
  3. // Information on the X BitMap (XBM) format can be found here:
  4. // https://en.wikipedia.org/wiki/X_BitMap
  5. // This example is part of the TFT_eSPI library:
  6. // https://github.com/Bodmer/TFT_eSPI
  7. // Created by Bodmer 23/14/18
  8. #include <M5Stack.h> // Hardware-specific library
  9. #include "xbm.h" // Sketch tab header for xbm images
  10. void setup() {
  11. M5.begin(); // Initialise the display
  12. M5.Power.begin();
  13. M5.Lcd.fillScreen(TFT_BLACK); // Black screen fill
  14. }
  15. void loop() {
  16. // Example 1
  17. // =========
  18. // Random x and y coordinates
  19. int x = random(M5.Lcd.width() - logoWidth);
  20. int y = random(M5.Lcd.height() - logoHeight);
  21. // Draw bitmap with top left corner at x,y with foreground only color
  22. // Bits set to 1 plot as the defined color, bits set to 0 are not plotted
  23. // x y xbm xbm width xbm height color
  24. M5.Lcd.drawXBitmap(x, y, logo, logoWidth, logoHeight, TFT_WHITE);
  25. delay(500);
  26. // Erase old one by drawing over with background colour
  27. M5.Lcd.drawXBitmap(x, y, logo, logoWidth, logoHeight, TFT_BLACK);
  28. // Example 2
  29. // =========
  30. // New random x and y coordinates
  31. x = random(M5.Lcd.width() - logoWidth);
  32. y = random(M5.Lcd.height() - logoHeight);
  33. // Draw bitmap with top left corner at x,y with foreground and background
  34. // colors Bits set to 1 plot as the defined fg color, bits set to 0 are
  35. // plotted as bg color
  36. // x y xbm xbm width xbm height fg color bg color
  37. M5.Lcd.drawXBitmap(x, y, logo, logoWidth, logoHeight, TFT_WHITE, TFT_RED);
  38. delay(500);
  39. // Erase old one by drawing over with background colour
  40. M5.Lcd.drawXBitmap(x, y, logo, logoWidth, logoHeight, TFT_BLACK, TFT_BLACK);
  41. }