Skip to content

Commit 110e8f4

Browse files
committed
fade the lcd on at powerup
1 parent 8d81b50 commit 110e8f4

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

atmega/atmega.ino

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,38 @@ void disableDisplay() {
235235
}
236236

237237
void initBacklight() {
238+
// TPS61160 init sequence
238239
setPinLow(LCD_CONTROL);
239240
delayMicroseconds(T_OFF);
240241
setPinHigh(LCD_CONTROL);
241242
delayMicroseconds(150);
242243
setPinLow(LCD_CONTROL);
243244
delayMicroseconds(300);
244245
setPinHigh(LCD_CONTROL);
246+
247+
// Fade from off to target brightness. Unnecessary, but looks nice.
248+
uint8_t targetRaw = i2cdata.status.brightness * 4 + 1;
249+
for (uint8_t rawBrightness = 1; rawBrightness <= targetRaw; rawBrightness++) {
250+
byte bytesToSend[] = {LCD_ADDR, rawBrightness};
251+
252+
noInterrupts();
253+
for (int byte = 0; byte < 2; byte++) {
254+
delayMicroseconds(T_START);
255+
for (int i = 7; i >= 0; i--) {
256+
bool bit = bytesToSend[byte] & (1 << i);
257+
setPinLow(LCD_CONTROL);
258+
delayMicroseconds(bit ? T_L_HB : T_L_LB);
259+
setPinHigh(LCD_CONTROL);
260+
delayMicroseconds(bit ? T_H_HB : T_H_LB);
261+
}
262+
setPinLow(LCD_CONTROL);
263+
delayMicroseconds(T_EOS);
264+
setPinHigh(LCD_CONTROL);
265+
}
266+
interrupts();
267+
268+
delay(20); // Fade step timing
269+
}
245270
}
246271

247272
void readSPIButtons() {
@@ -332,7 +357,6 @@ void toggleAudioCircuit() {
332357

333358
void enableDisplay() {
334359
initBacklight();
335-
setBrightness();
336360
}
337361

338362
void heartbeatLED() {

0 commit comments

Comments
 (0)