Hello
I am new in that area.
I have 3pi and want to read port ADC2 (reflactance sensor 2 only PC2), and to show result on display.
But there is result “0”.
When I change to read ADC7 (pot 10K), everything work. Display show from to 1023.
Can you help me?
- Is it correct "analog_read(2); " is ADC2
- Is it correct source code for power on the IR ( PORTC |= 1 << 5;)
That is my source code.
#include <pololu/orangutan.h>
int main()
{
set_analog_mode(MODE_10_BIT); // 10-bit analog-to-digital conversions
clear();
// set the port to output PC5
DDRC |= 1 << 5;
// high to power on IR on 3pi PC5
PORTC |= 1 << 5;
int sum = 0;
int samples = 0;
int avg = 0;
analog_read(2); // start initial conversion for ADC2
while(1)
{
delay_ms(10);
clear();
print_long(avg);
if (!analog_is_converting()) // if conversion is done…
{
sum += analog_conversion_result(); // get result
start_analog_conversion(2); // start next conversion
if (++samples == 20) // if 20 samples have been taken…
{
avg = sum / 20; // compute 20-sample average of ADC result
samples = 0;
sum = 0;
}
}
}
}
Thanks