Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <p18f242.h>
#include <adc.h>
#include <delays.h>
int result;
void main( void )
{
// 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;
#define RED 102
#define BLUE 204
if(result < RED)
{
PORTB = 0b10000000;
}
else if(RED< result < BLUE)
{
PORTB = 0b01000000;
}
else if(result >BLUE )
{
PORTB = 0b00100000;
}
}
}
#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;
}
}
}