ATtinyWatch
ATtinyWatch copied to clipboard
Display style
Hi,
this version is with battery and temp, do you have also teh "old" version without battery and temp? And bigger time?
void draw_oled() {
if (display_mode != last_display_mode) {
oled.fill(0x00);
last_display_mode = display_mode;
}
oled.set_font_size(1);
if (display_mode == time_mode) {
// 1st row: print info
oled.set_pos(0, 0);
oled.print(getTemp() / 1000);
oled.draw_pattern(1, 0b00000010);
oled.draw_pattern(1, 0b00000101);
oled.draw_pattern(1, 0b00000010);
oled.write('C');
// top right corner: battery status
uint32_t vcc = getVcc();
// show battery bar from 1.8 V to 3.0 V in 8 pixels, (3000 - 1800) / 8 = 150
uint8_t bat_level = (vcc >= 3000) ? 8 : ((vcc <= 1800) ? 1 : ((vcc - 1800 + 150) / 150));
oled.draw_pattern(51, 0, 1, 1, 0b00111111);
oled.draw_pattern(1, 0b00100001);
oled.draw_pattern(bat_level, 0b00101101);
oled.draw_pattern(8 + 1 - bat_level, 0b00100001);
oled.draw_pattern(1, 0b00111111);
oled.draw_pattern(1, 0b00001100);
// 2nd row: print date
print_digit(7, 1, year(), (selected_field == YEAR_FIELD));
oled.write('-');
print_digit(7 + (5 * FONT_WIDTH), 1, month(), (selected_field == MONTH_FIELD));
oled.write('-');
print_digit(7 + (8 * FONT_WIDTH), 1, day(), (selected_field == DAY_FIELD));
// 3rd-4th rows: print time
oled.set_font_size(2);
print_digit(0, 2, hour(), (selected_field == HOUR_FIELD));
oled.draw_pattern(2 * FONT_2X_WIDTH + 1, 2, 2, 2, 0b00011000);
print_digit(2 * FONT_2X_WIDTH + 5, 2, minute(), (selected_field == MINUTE_FIELD));
oled.draw_pattern(4 * FONT_2X_WIDTH + 6, 2, 2, 2, 0b00011000);
print_digit(4 * FONT_2X_WIDTH + 2 * FONT_WIDTH, 2, second(), (selected_field == SECOND_FIELD));
} else if (display_mode == debug_mode) { // debug_mode
print_debug_value(0, 'I', get_wdt_interrupt_count());
print_debug_value(1, 'M', get_wdt_microsecond_per_interrupt());
print_debug_value(2, 'V', getVcc());
print_debug_value(3, 'T', getRawTemp());
} // debug_mode
}
void print_digit(uint8_t col, uint8_t page, int value, bool invert_color) {
oled.set_pos(col, page);
if (invert_color) oled.set_invert_color(true);
if (value < 10) oled.write('0');
oled.print(value);
if (invert_color) oled.set_invert_color(false);
}
void print_debug_value(uint8_t page, char initial, uint32_t value) {
oled.set_pos(0, page);
oled.write(initial);
oled.set_pos(14, page);
oled.print(value);
}