Advertisement
N3v1em

Encoder Controled Menu

Nov 4th, 2024 (edited)
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.39 KB | None | 0 0
  1. #include <TFT_eSPI.h>
  2. #include <pgmspace.h>
  3. #include "AiEsp32RotaryEncoder.h"
  4. #include "Arduino.h"
  5.  
  6. #define ROTARY_ENCODER_A_PIN 35
  7. #define ROTARY_ENCODER_B_PIN 32
  8. #define ROTARY_ENCODER_BUTTON_PIN 34
  9. #define ROTARY_ENCODER_VCC_PIN -1
  10. #define ROTARY_ENCODER_STEPS 4
  11.  
  12. AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, ROTARY_ENCODER_VCC_PIN, ROTARY_ENCODER_STEPS);
  13. TFT_eSPI tft = TFT_eSPI();
  14.  
  15. // Initialize the display
  16. // Image data stored in PROGMEM (add width and height of the image)
  17. static const unsigned char PROGMEM image_Arrow_Icon_bits[] = {0x30,0x06,0x00,0x78,0x0f,0x00,0xfc,0x1f,0x80,0xfe,0x1f,0xc0,0x7f,0x0f,0xe0,0x3f,0x87,0xf0,0x1f,0xc3,0xf8,0x0f,0xe1,0xfc,0x07,0xf0,0xfe,0x03,0xf8,0x7f,0x03,0xf8,0x7f,0x07,0xf0,0xfe,0x0f,0xe1,0xfc,0x1f,0xc3,0xf8,0x3f,0x87,0xf0,0x7f,0x0f,0xe0,0xfe,0x1f,0xc0,0xfc,0x1f,0x80,0x78,0x0f,0x00,0x30,0x06,0x00};
  18. static const unsigned char PROGMEM image_Moon_Icon_bits[] = {0x01,0xf0,0x00,0x07,0xf0,0x00,0x0f,0xe0,0x00,0x1f,0x80,0x00,0x3f,0x80,0x00,0x7f,0x00,0x00,0x7f,0x00,0x00,0xff,0x00,0x00,0xff,0x00,0x00,0xff,0x00,0x00,0xff,0x00,0x00,0xff,0x00,0x06,0xff,0x80,0x0e,0xff,0xc0,0x1e,0xff,0xe0,0x3e,0x7f,0xff,0xfc,0x7f,0xff,0xfc,0x3f,0xff,0xfc,0x3f,0xff,0xf8,0x1f,0xff,0xf0,0x07,0xff,0xe0,0x01,0xff,0xc0,0x00,0xfe,0x00};
  19. static const unsigned char PROGMEM image_Settings_Icon_bits[] = {0x00,0x7c,0x00,0x00,0x7c,0x00,0x04,0xfe,0x40,0x0f,0xff,0xe0,0x1f,0xff,0xf0,0x3f,0xff,0xf8,0x1f,0xc7,0xf0,0x1f,0x01,0xf0,0x3e,0x00,0xf8,0xfe,0x00,0xfe,0xfc,0x38,0x7e,0xfc,0x38,0x7e,0xfc,0x38,0x7e,0xfe,0x00,0xfe,0x3e,0x00,0xf8,0x1f,0x01,0xf0,0x1f,0xc7,0xf0,0x3f,0xff,0xf8,0x1f,0xff,0xf0,0x0f,0xff,0xe0,0x04,0xfe,0x40,0x00,0x7c,0x00,0x00,0x7c,0x00};
  20. static const unsigned char PROGMEM image_Stats_Icon_bits[] = {0x07,0x00,0x00,0x07,0x00,0x00,0x07,0x00,0x00,0xe7,0x00,0x00,0xe7,0x00,0x00,0xe7,0x38,0x00,0xe7,0x38,0x00,0xe7,0x38,0x00,0xe7,0x38,0x00,0xe7,0x39,0xc0,0xe7,0x39,0xc0,0xe7,0x39,0xc0,0xe7,0x39,0xc0,0xe7,0x39,0xc0,0xe7,0x39,0xc0,0xe7,0x39,0xc0,0xe7,0x39,0xc0,0xe7,0x39,0xc0,0xe7,0x39,0xc0,0xe7,0x39,0xc0};
  21. static const unsigned char PROGMEM image_Selector_bits[] = {0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x00,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x00,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0x80,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0x80,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x80,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0x80,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0x00,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x00,0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x00};
  22.  
  23. int overlay = TFT_WHITE;
  24. int overlay_selected = TFT_YELLOW;
  25. int background = TFT_BLACK;
  26.  
  27. int Start_Color = overlay;
  28. int Sleep_Color = overlay;
  29. int Settings_Color = overlay;
  30. int Stats_Color = overlay;
  31.  
  32. int Arrow_Icon = overlay;
  33. int Moon_Icon = overlay;
  34. int Settings_Icon = overlay;
  35. int Stats_Icon = overlay;
  36.  
  37. int Selector_Icon1 = background;
  38. int Selector_Icon2 = background;
  39. int Selector_Icon3 = background;
  40. int Selector_Icon4 = background;
  41.  
  42. int Selector_Position1 = 1;
  43. int Selector_Position2 = 61;
  44. int Selector_Position3 = 121;
  45. int Selector_Position4 = 182;
  46.  
  47. bool main_menu = true;
  48.  
  49. void rotary_onButtonClick()
  50. {
  51. static unsigned long lastTimePressed = 0; // Soft debouncing
  52. if (millis() - lastTimePressed < 500)
  53. {
  54. return;
  55. }
  56. lastTimePressed = millis();
  57. Serial.print("button pressed ");
  58. Serial.println(millis());
  59. }
  60.  
  61.  
  62. void rotary_loop()
  63. {
  64. //dont print anything unless value changed
  65. if (rotaryEncoder.encoderChanged())
  66. {
  67. Serial.print("Value: ");
  68. Serial.println(rotaryEncoder.readEncoder());
  69. }
  70. if (rotaryEncoder.isEncoderButtonClicked())
  71. {
  72. rotary_onButtonClick();
  73. }
  74. }
  75.  
  76. void IRAM_ATTR readEncoderISR()
  77. {
  78. rotaryEncoder.readEncoder_ISR();
  79. }
  80.  
  81. void setup()
  82. {
  83. Serial.begin(115200);
  84.  
  85. //we must initialize rotary encoder
  86. rotaryEncoder.begin();
  87. rotaryEncoder.setup(readEncoderISR);
  88. //set boundaries and if values should cycle or not
  89. //in this example we will set possible values between 0 and 1000;
  90. bool circleValues = false;
  91. rotaryEncoder.setEncoderValue(1);
  92. rotaryEncoder.setBoundaries(1, 4, circleValues); //minValue, maxValue, circleValues true|false (when max go to min and vice versa)
  93. rotaryEncoder.disableAcceleration(); //acceleration is now enabled by default - disable if you dont need it
  94. rotaryEncoder.setAcceleration(250); //or set the value - larger number = more accelearation; 0 or 1 means disabled acceleration
  95. tft.begin(); // Initialize the TFT
  96. tft.setRotation(1); // Adjust rotation if necessary
  97. tft.fillScreen(background); // Clear screen to black
  98. }
  99.  
  100. void loop(){
  101.  
  102. while (main_menu == true){
  103.  
  104. if (rotaryEncoder.readEncoder() == 1){
  105. // Start
  106. // Selector_Position = 1;
  107. Start_Color = overlay_selected;
  108. Sleep_Color = overlay;
  109. Settings_Color = overlay;
  110. Stats_Color = overlay;
  111.  
  112. Arrow_Icon = overlay_selected;
  113. Moon_Icon = overlay;
  114. Settings_Icon = overlay;
  115. Stats_Icon = overlay;
  116.  
  117. Selector_Icon1 = overlay_selected;
  118. Selector_Icon2 = background;
  119. Selector_Icon3 = background;
  120. Selector_Icon4 = background;
  121.  
  122. }
  123.  
  124. if (rotaryEncoder.readEncoder() == 2){
  125. // Sleep
  126. // Selector_Position = 61;
  127. Start_Color = overlay;
  128. Sleep_Color = overlay_selected;
  129. Settings_Color = overlay;
  130. Stats_Color = overlay;
  131.  
  132. Arrow_Icon = overlay;
  133. Moon_Icon = overlay_selected;
  134. Settings_Icon = overlay;
  135. Stats_Icon = overlay;
  136.  
  137. Selector_Icon1 = background;
  138. Selector_Icon2 = overlay_selected;
  139. Selector_Icon3 = background;
  140. Selector_Icon4 = background;
  141.  
  142. }
  143.  
  144. if (rotaryEncoder.readEncoder() == 3){
  145. // Settings
  146. // Selector_Position = 121;
  147. Start_Color = overlay;
  148. Sleep_Color = overlay;
  149. Settings_Color = overlay_selected;
  150. Stats_Color = overlay;
  151.  
  152. Arrow_Icon = overlay;
  153. Moon_Icon = overlay;
  154. Settings_Icon = overlay_selected;
  155. Stats_Icon = overlay;
  156.  
  157. Selector_Icon1 = background;
  158. Selector_Icon2 = background;
  159. Selector_Icon3 = overlay_selected;
  160. Selector_Icon4 = background;
  161.  
  162. }
  163.  
  164. if (rotaryEncoder.readEncoder() == 4){
  165. // Stats
  166. // Selector_Position = 182;
  167. Start_Color = overlay;
  168. Sleep_Color = overlay;
  169. Settings_Color = overlay;
  170. Stats_Color = overlay_selected;
  171.  
  172. Arrow_Icon = overlay;
  173. Moon_Icon = overlay;
  174. Settings_Icon = overlay;
  175. Stats_Icon = overlay_selected;
  176.  
  177. Selector_Icon1 = background;
  178. Selector_Icon2 = background;
  179. Selector_Icon3 = background;
  180. Selector_Icon4 = overlay_selected;
  181. }
  182.  
  183. tft.drawBitmap(23, 19, image_Arrow_Icon_bits, 24, 20, Arrow_Icon);
  184. tft.drawBitmap(23, 78, image_Moon_Icon_bits, 23, 23, Moon_Icon);
  185. tft.drawBitmap(23, 138, image_Settings_Icon_bits, 23, 23, Settings_Icon);
  186. tft.drawBitmap(26, 200, image_Stats_Icon_bits, 18, 20, Stats_Icon);
  187. tft.drawBitmap(4, Selector_Position1, image_Selector_bits, 313, 57, Selector_Icon1);
  188. tft.drawBitmap(4, Selector_Position2, image_Selector_bits, 313, 57, Selector_Icon2);
  189. tft.drawBitmap(4, Selector_Position3, image_Selector_bits, 313, 57, Selector_Icon3);
  190. tft.drawBitmap(4, Selector_Position4, image_Selector_bits, 313, 57, Selector_Icon4);
  191.  
  192. tft.setTextSize(3);
  193. tft.setFreeFont();
  194.  
  195. tft.setTextColor(Start_Color);
  196. tft.drawString("Start", 70, 18);
  197.  
  198. tft.setTextColor(Sleep_Color);
  199. tft.drawString("Sleep", 70, 78);
  200.  
  201. tft.setTextColor(Settings_Color);
  202. tft.drawString("Settings", 70, 138);
  203.  
  204. tft.setTextColor(Stats_Color);
  205. tft.drawString("Stats", 70, 199);
  206.  
  207. rotary_loop();
  208. delay(10); //or do whatever you need to do...
  209.  
  210.  
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement