X-Git-Url: https://defiant.homedns.org/gitweb/?p=ros_wild_thumper.git;a=blobdiff_plain;f=avr%2Fnano%2Fmain.c;h=76ce35a409dd469e05e7be67f4463803b2919251;hp=5418055daaf734023e65215f000ce8156d064300;hb=003b8804848207a2403a7e879fc86f34eb631152;hpb=a4e84ce5a9d3245334956b761e319f9f52ee162f diff --git a/avr/nano/main.c b/avr/nano/main.c index 5418055..76ce35a 100644 --- a/avr/nano/main.c +++ b/avr/nano/main.c @@ -18,6 +18,8 @@ * 0x06 Distance forward LSB * 0x07 Distance backward MSB * 0x08 Distance backward LSB + * 0x09 Voltage MSB + * 0x0A Voltage LSB * * 0xff Bootloader */ @@ -35,6 +37,7 @@ static volatile uint16_t dist_forward=0; static volatile uint16_t dist_backward=0; static volatile uint8_t start_dist_fwd=0; static volatile uint8_t start_dist_bwd=0; +static volatile uint16_t voltage=0; ISR(TWI_vect) { @@ -103,6 +106,15 @@ ISR(TWI_vect) TWDR = tmp16; TWI_ACK; break; + case 0x09: // Voltage MSB + tmp16 = voltage; + TWDR = tmp16>>8; + TWI_ACK; + break; + case 0x0A: // Voltage LSB + TWDR = tmp16; + TWI_ACK; + break; default: TWDR = 0; TWI_NAK; @@ -159,6 +171,11 @@ static unsigned short get_distance(uint8_t i) { } +static unsigned short get_voltage(void) { + return ReadChannel(2)*1.46; +} + + ISR(INT0_vect) { static uint16_t t_start=0; uint16_t t_now = TCNT1; @@ -221,6 +238,9 @@ int main(void) { case 0x03: // ir right dist_right = get_distance(1); break; + case 0x09: // voltage + voltage = get_voltage(); + break; case 0xff: // Magic reg that starts the bootloader if (bootloader == 0xa5) { cli();