#define RED 102U
#define BLUE 204U
#define MIN 0U
#define MAX 256U
void main(void)
{
unsigned int result;
// configure A/D convertor
OpenADC( ADC_FOSC_RC & ADC_LEFT_JUST & ADC_8ANA_0REF,
ADC_CH0 & ADC_INT_OFF );
while(1)
{
Delay10TCYx( 5 ); // Delay
ConvertADC(); // Start conversion
while(BusyADC()); // Wait for completion
result = ReadADC(); // Read result
// CloseADC(); // Disable A/D converter
TRISB = 0;
if(result < RED)
{
PORTB = 0b10000000;
}
else if(result < BLUE)
{
PORTB = 0b01000000;
}
else
{
PORTB = 0b00100000;
}
}
}