Log in

View Full Version : Pot Printf Variable


Idaman323
17-02-2006, 22:56
Hey guys, just got a quick question. I have a command to tell me the range of our potentiometer. Its a printf command. I have gotten the adc code all up in the code already. It goes something like:

printf("Pot value: %d\r\n", variableNameUsedForPot);

Except, Im not sure what the actual variable name is. Can someone maybe tell me real quick I cant find it in the code. Thanks!

Bob Koehl
17-02-2006, 23:00
See this example from the IFI programming guide (2004-programming-reference-guide-12-apr-2004.pdf) page 16:
/* Example of using the Analog Inputs to map an analog input to a PWM output. */
unsigned int sensor1;
unsigned char sensor1_8bits;
sensor1 = Get_Analog_Value( rc_ana_in01 ); /* Assign the analog reading to a variable. */
sensor1_8bits = (unsigned char)(sensor1 >> 2); /* Only take the 8 most significant bits, */
pwm01 = sensor1_8bits; /* because PWM OUTPUTS can only be 8 bits. *

printf("Pot value: %d\r\n", variableNameUsedForPot);
would be
printf("Pot value: %d\r,(int)sensor1);

Hope this helps.

Idaman323
17-02-2006, 23:55
So pretty much I can do

unsigned int sensor1;

sensor1 = Get_Analog_Value( rc_ana_in01 ); /* Assign the analog reading to a variable. */

then in proccess_data_from_master_up we put the

printf("Pot value: %d\r,(int)sensor1);


would that work, and would the top part go into adc.h or adc.c?

Ryan M.
18-02-2006, 07:17
would that work, and would the top part go into adc.h or adc.c?You should place the sensor declaration whereever you are going to be using it. If it needs to be in multiple places, put an extern declaration in a header file which you then include in the extra files. IE:

externDeclartion.h (or whatever you want to call it)extern unsigned int sensor1;someFile.c#include "externDeclaration.h"
...

--EDIT--
And yeah, you have the idea.

kevlarman
18-02-2006, 10:48
if you have kevin watson's adc code set up then you should use Get_ADC_Result(1) instead of Get_Analog_Value( rc_ana_in01 )