From f6e7d4fd15bc1adb538d4b4f053a7ac43f8bb2fe Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 6 Mar 2020 21:55:30 +0100 Subject: ws2812b_uart: monitor VCC --- src/app/ws2812b_uart/main.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/app/ws2812b_uart') diff --git a/src/app/ws2812b_uart/main.cc b/src/app/ws2812b_uart/main.cc index b35800a..791e67a 100644 --- a/src/app/ws2812b_uart/main.cc +++ b/src/app/ws2812b_uart/main.cc @@ -226,6 +226,17 @@ int main(void) target_mode = blinkencat.COLOR_RGB; } } + if (ADCSRA & _BV(ADIF)) { + uint8_t adcr_l = ADCL; + uint8_t adcr_h = ADCH; + uint16_t adcr = adcr_l + (adcr_h << 8); + uint16_t vcc = 1100L * 1023 / adcr; + + TIFR1 |= _BV(TOV1); + ADCSRA |= _BV(ADIF); + + kout << "VCC = " << vcc << endl; + } } return 0; -- cgit v1.2.3