SSD1306UiDemo.ino 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
  2. #include "heltec.h" // alias for `#include "SSD1306Wire.h"
  3. #include "images.h"
  4. #define DEMO_DURATION 3000
  5. typedef void (*Demo)(void);
  6. OLEDDisplayUi ui ( Heltec.display );
  7. void msOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
  8. display->setTextAlignment(TEXT_ALIGN_RIGHT);
  9. display->setFont(ArialMT_Plain_10);
  10. display->drawString(128, 0, String(millis()));
  11. }
  12. void drawFrame1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  13. display->drawXbm(x, y, BT_width, BT_height, BT_bits);
  14. display->drawXbm(x + 12 + 1, y, WIFI_width, WIFI_height, WIFI_bits);
  15. display->drawXbm(x + 108, y, BAT_width, BAT_height, BAT_bits);
  16. display->setFont(ArialMT_Plain_24);
  17. display->drawString(x + 28, y + 5, "HelTec");
  18. }
  19. void drawFrame2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  20. //display->drawXbm(x, y, BT_width, BT_height, BT_bits);
  21. //display->drawXbm(x + 12 + 1, y, WIFI_width, WIFI_height, WIFI_bits);
  22. //display->drawXbm(x + 108, y, BAT_width, BAT_height, BAT_bits);
  23. display->drawString(x + 10, y + 5, "WIFI KIT 8");
  24. }
  25. void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  26. display->drawXbm(x + 25, y, HelTec_LOGO_width, HelTec_LOGO_height, HelTec_LOGO_bits);
  27. }
  28. void drawFrame4(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  29. display->setTextAlignment(TEXT_ALIGN_LEFT);
  30. //display->setFont(ArialMT_Plain_16);
  31. //display->drawString(x, y, "HelTec");
  32. display->setFont(ArialMT_Plain_10);
  33. display->drawString(x, y , "HelTec AutoMation");
  34. display->drawString(x, y + 10, "www.heltec.cn");
  35. }
  36. FrameCallback frames[] = { drawFrame1, drawFrame2, drawFrame3, drawFrame4 };
  37. int frameCount = 4;
  38. //OverlayCallback overlays[] = { msOverlay };
  39. //int overlaysCount = 1;
  40. void setup() {
  41. Heltec.begin(true /*DisplayEnable Enable*/, true /*Serial Enable*/);
  42. ui.setTargetFPS(30);
  43. // Customize the active and inactive symbol
  44. ui.setActiveSymbol(activeSymbol);
  45. ui.setInactiveSymbol(inactiveSymbol);
  46. // You can change this to
  47. // TOP, LEFT, BOTTOM, RIGHT
  48. ui.setIndicatorPosition(BOTTOM);
  49. // Defines where the first frame is located in the bar.
  50. ui.setIndicatorDirection(LEFT_RIGHT);
  51. // You can change the transition that is used
  52. // SLIDE_LEFT, SLIDE_RIGHT, SLIDE_UP, SLIDE_DOWN
  53. ui.setFrameAnimation(SLIDE_LEFT);
  54. // Add frames
  55. ui.setFrames(frames, frameCount);
  56. // Add overlays
  57. // ui.setOverlays(overlays, overlaysCount);
  58. // Initialising the UI will init the display too.
  59. ui.init();
  60. Heltec.display->flipScreenVertically();
  61. }
  62. void loop() {
  63. int remainingTimeBudget = ui.update();
  64. if (remainingTimeBudget > 0) {
  65. // You can do some work here
  66. // Don't do stuff if you are below your
  67. // time budget.
  68. delay(remainingTimeBudget);
  69. }
  70. }