Created
February 12, 2024 07:46
-
-
Save santolucito/490c682c0f730a78d2a321037745929c to your computer and use it in GitHub Desktop.
ESP32 TTGO T1 power demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this code will show you the battery charge left on the screen | |
//and dim the screen (to conserve power) | |
//and go to sleep when you press the left builtin button | |
//to wake it up again, just hit the reset button on the side | |
//download as zip and add to libraries folder in Arduino folder https://github.com/pangodream/18650CL | |
#include <Pangodream_18650_CL.h> | |
#define ADC_PIN 34 | |
#define CONV_FACTOR 1.8 | |
#define READS 20 | |
Pangodream_18650_CL BL(ADC_PIN, CONV_FACTOR, READS); | |
#include <TFT_eSPI.h> | |
#include <SPI.h> | |
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h | |
#define BUTTON_PIN_BITMASK 0x800000000 // 2^35 in hex | |
void IRAM_ATTR goToSleep() { | |
esp_deep_sleep_start(); | |
} | |
void setup() { | |
tft.init(); | |
tft.setRotation(1); | |
attachInterrupt(0, goToSleep, CHANGE); | |
//set screen Back Light brightness | |
pinMode(TFT_BL, OUTPUT); | |
ledcSetup(0, 5000, 8); // 0-15, 5000, 8 | |
ledcAttachPin(TFT_BL, 0); // TFT_BL, 0 - 15 | |
ledcWrite(0, 1); // 0-15, 0-255 (with 8 bit resolution); 0=totally dark;255=totally shiny | |
} | |
void loop() { | |
tft.fillScreen(TFT_BLACK); | |
tft.setTextColor(TFT_WHITE, TFT_BLACK); | |
tft.drawFloat(BL.getBatteryChargeLevel(), 3, 0, 80, 4); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment