-
Screen Brightness
10/18/2025 at 04:12 • 0 commentsSince there are a couple of buttons on the T-Display I thought we could add a brightness adjustment. Just click the button and cycle through 4 brightness levels.
How It Works
- PWM Control: Uses ESP32's LED Control (LEDC) peripheral to generate PWM signal on the backlight pin 4
- Brightness Levels: 10%, 40%, 70%, and 100% mapped to PWM values 26, 102, 179, and 255 Button
- Detection: Both buttons (GPIO 0 and GPIO 14) are configured with internal pullups (active LOW)
- Debouncing: 200ms delay prevents accidental multiple presses
- Cycling: Each button press cycles to the next brightness level and wraps around
Code Snippets for Button Press Backlight Control
1. Pin Definitions
Add these button pin definitions at the top with your other pins:
// Pin definitions #define PIN_LCD_BL 38 // Backlight pin #define PIN_BUTTON_1 0 // Boot button #define PIN_BUTTON_2 14 // Second button
2. Global Variables
Define brightness levels and state tracking:
// Brightness control const uint8_t brightnessLevels[] = {26, 102, 179, 255}; // 10%, 40%, 70%, 100% const char* brightnessLabels[] = {"10%", "40%", "70%", "100%"}; int currentBrightnessIndex = 3; // Start at 100% unsigned long lastButtonPress = 0; const unsigned long buttonDebounce = 200; // 200ms debounce3. Forward Declarations
Add function declarations:
void setBrightness(int index); void checkButtons();
4. Setup - Initialize PWM Backlight
Replace the simple
digitalWrite()backlight control with PWM in yoursetup():void setup() { // ... other setup code ... // Initialize backlight with PWM ledcSetup(0, 5000, 8); // Channel 0, 5kHz, 8-bit resolution ledcAttachPin(PIN_LCD_BL, 0); setBrightness(currentBrightnessIndex); // Set to initial brightness (100%) Serial.print("Backlight initialized at "); Serial.print(brightnessLabels[currentBrightnessIndex]); Serial.println(" brightness"); // Initialize buttons pinMode(PIN_BUTTON_1, INPUT_PULLUP); pinMode(PIN_BUTTON_2, INPUT_PULLUP); Serial.println("Buttons initialized"); // ... rest of setup ... }5. Loop - Check Buttons
Add button checking in your main
loop():void loop() { // ... other loop code ... // Check for button presses to adjust brightness checkButtons(); // ... rest of loop ... }6. setBrightness() Function
Set the backlight brightness using PWM:
void setBrightness(int index) { if (index < 0 || index >= 4) return; ledcWrite(0, brightnessLevels[index]); currentBrightnessIndex = index; }7. checkButtons() Function
Handle button presses with debouncing:
// Check for button presses and cycle brightness void checkButtons() { unsigned long now = millis(); // Debounce check if (now - lastButtonPress < buttonDebounce) { return; } // Check if either button is pressed (active LOW with pullup) bool button1Pressed = digitalRead(PIN_BUTTON_1) == LOW; bool button2Pressed = digitalRead(PIN_BUTTON_2) == LOW; if (button1Pressed || button2Pressed) { lastButtonPress = now; // Cycle to next brightness level currentBrightnessIndex = (currentBrightnessIndex + 1) % 4; setBrightness(currentBrightnessIndex); Serial.print("Brightness changed to: "); Serial.println(brightnessLabels[currentBrightnessIndex]); } } -
BlueSky API Pains
10/18/2025 at 03:06 • 0 commentsSo connecting to BlueSky is super easy, and calling the API and pulling posts based off hashtags is no problem. Even pulling recent posts, which is what we are doing, is easy peasy. However, I kept having an issue and it would only pull a single most recent post, then the next two were 15 days old.
So I took to the BlueSky website and did the search on the site and sorted by latest and got the same result. The interesting thing is that the first post it showed was in fact the most recent post, but the second was 15 days old, and the next was chronologically the next post to that one. The interesting thing was that the 15 day old post was pinned. After messing around a bit with trying to pull the posts in different methods with the API, it seems like somehow the pinned post messes up a few posts following it, then returns back to the actual "most recent" order.
Why is this? I don't know. It seems like it was only doing this to the pinned post plus 6 more. The pinned post was from seagl.org, which makes sense, but is a pain none-the-less. Thankfully this was a number of posts we could overcome. With the hardware limits of the ESP32 we could only pull 10 posts at a time, so basically we pull 10 posts and ignore any posts from @seagl.org and use the 3 most recent posts remaining.
So is this my ideal operation? No, but it does allow the tool to work and does still scoop up the community posts related to the event, so still a win in my book.
JohnsonFarms.us