#include "main.h"


void main()
{
   int16 ble;

   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_4,254,1);
   setup_ccp1(CCP_PWM);
   setup_ccp2(CCP_PWM);
   set_pwm1_duty(1023);
   set_pwm2_duty(1023);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   port_b_pullups (TRUE);

   set_adc_channel(0);
   delay_us(20);
   
   while(TRUE)
   {
      while(!input(PIN_B7));
      ble=read_adc(); 
      set_pwm1_duty(ble);
      set_pwm2_duty(1023-ble);
      printf("* %lu *\n\r", ble);
      delay_ms(200);
      set_pwm2_duty(ble);
      set_pwm1_duty(1023-ble);
      delay_ms(200);      
   }
}