#include ".\MAINW4.h"

#define gm      PIN_A4      // tady by mely byt pulzy
#define pip1       PIN_C4     //cvakani
#define pip2       PIN_C5      //cvakani taky/opacne, aby to cvakalo vic nahlas
//#define pip1(false)
//#define pip2(true)
//#define pip1 output_high    //vystupy inverzne
//#define pip2 output_low


void main()
{
int8 pocet;
int8 delay;


   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_DIV_1|RTCC_EXT_L_TO_H);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DIV_BY_1,255,1);
   setup_ccp1(CCP_PWM);
   setup_ccp2(CCP_PWM);
   set_pwm1_duty(0);
   set_pwm2_duty(0);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   

   //set_timer0(0);   
   pocet=0;
   while(TRUE)
   {
      delay=read_adc();
      set_pwm1_duty(delay);
      set_pwm2_duty(delay); 
      
     
     
      
     //if(get_timer0())    // jestli zmena  na vystuppu trubice, tak citni

        if(input(gm))
         {
             
            //pocet=(get_timer0());      //  tak pocitej do promeny pocet    
            pocet++;                   //pricti 1
               output_low(pip1); //vystupy inverzne do zeme a  na Vdd
               delay_ms(10);
               output_low(pip2);
               delay_ms(10);
               //output_high(pip1);    
               //output_low(pip2);
               //delay_ms(10);

          }
   } 

//delay_ms(6000);    
printf("%d",pocet);           
}