View Single Post
  #10   Spotlight this post!  
Unread 29-01-2007, 00:49
bear24rw's Avatar
bear24rw bear24rw is offline
Team 11 Programming Captain
AKA: Max T
FRC #0011 (MORT)
Team Role: Programmer
 
Join Date: Sep 2005
Rookie Year: 2005
Location: Flanders, NJ
Posts: 385
bear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to behold
Send a message via AIM to bear24rw
Re: Reading battery voltage in software

Wrote this over the summer when playing around with the edu rc. It prints out a float
Code:
current_voltage = rxdata.rc_main_batt; 		// Store current voltage
	average_voltage += current_voltage;		// Add the current voltage to the average stack

	voltage_count++;							// Increase the average stack count
	
	if (voltage_count == 39)					      // If the stack is 40
	{
		average_voltage = (average_voltage / 40) * 0.038 + 0.05;	// Get the average and apply formula
		i = (int)average_voltage;							// Truncate decimals
		i2 = (int) ((average_voltage - i) * 1000);				// Subtract to get decimals only and then multiply by 1000
		printf("Average: %d.%d \n",i,i2);						// Print the two together to make it look like a decimal

		average_voltage = 0;									// Reset the stack
		voltage_count = 0;									// Rest the counter
	}

Last edited by bear24rw : 29-01-2007 at 00:51.