Skip to content

Commit

Permalink
Update T-Deck keyboard example
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Dec 25, 2024
1 parent 9d15775 commit 94e8899
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions examples/Keyboard_T_Deck_Master/Keyboard_T_Deck_Master.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,40 @@
#include <Arduino.h>
#include <Wire.h>

#define LILYGO_KB_SLAVE_ADDRESS 0x55

#define LILYGO_KB_SLAVE_ADDRESS 0x55
#define LILYGO_KB_BRIGHTNESS_CMD 0x01
#define LILYGO_KB_ALT_B_BRIGHTNESS_CMD 0x02

#define BOARD_POWERON 10
#define BOARD_I2C_SDA 18
#define BOARD_I2C_SCL 8

/*
* Dynamically modify backlight brightness at runtime
* Brightness Range: 0 ~ 255
* */
void setKeyboardBrightness(uint8_t value)
{
Wire.beginTransmission(LILYGO_KB_SLAVE_ADDRESS);
Wire.write(LILYGO_KB_BRIGHTNESS_CMD);
Wire.write(value);
Wire.endTransmission();
}

/*
* Set the default backlight brightness level. If the user sets the backlight to 0
* via setKeyboardBrightness, the default brightness is used when pressing ALT+B,
* rather than the backlight brightness level set by the user. This ensures that
* pressing ALT+B can respond to the backlight being turned on and off normally.
* Brightness Range: 30 ~ 255
* */
void setKeyboardDefaultBrightness(uint8_t value)
{
Wire.beginTransmission(LILYGO_KB_SLAVE_ADDRESS);
Wire.write(LILYGO_KB_ALT_B_BRIGHTNESS_CMD);
Wire.write(value);
Wire.endTransmission();
}

void setup()
{
Expand All @@ -36,12 +63,16 @@ void setup()
Wire.requestFrom(LILYGO_KB_SLAVE_ADDRESS, 1);
if (Wire.read() == -1) {
while (1) {
Serial.println("LILYGO Keyboad not online .");
Serial.println("LILYGO Keyboard not online .");
delay(1000);
}
}
// Set the default backlight brightness level.
setKeyboardDefaultBrightness(127);

}

bool test_bl_done = false;
void loop()
{
// Read key value from esp32c3
Expand All @@ -54,6 +85,22 @@ void loop()
Serial.println(keyValue);
}
}

// Test brightness
static uint32_t interval = 0;
static uint8_t brightness = 0;
if (millis() > interval && !test_bl_done) {
// Dynamically modify backlight brightness at runtime
setKeyboardBrightness(brightness);
brightness++;
brightness %= 255;
if (brightness == 0) {
Serial.println("Test brightness done..., Press ALT+B test default brightness level");
setKeyboardBrightness(brightness);
test_bl_done = true;
}
interval = millis() + 50;
}
delay(5);
}

Expand Down

0 comments on commit 94e8899

Please sign in to comment.