예제 #1
0
파일: main.c 프로젝트: dad55/projet_bateau
void ADC_IT (void){			
		u16 y;

		if (ADC_ready(ADC1)){
			y=lire_ADC(ADC1);
		}
		if (ADC_ready(ADC2)){
			batterie = lire_ADC(ADC2);
		}
		angle = acos(((y*ADC_VDD/0xFFF)-(Y_AXIS_1g-ACCELERO_Sensitivity))/ACCELERO_Sensitivity)*180/PI;
		
		if ((angle>45)&&(alerte_roulis==0))
			alerte_roulis=1;
		else if((angle<44)&&(alerte_roulis==1))
			alerte_roulis=0;
		if ((batterie*ADC_VDD/0xFFF)<(VCC*0.8/VCC_ratio))
			alerte_batterie=1;
		else if ((batterie*ADC_VDD/0xFFF)>(VCC*0.81/VCC_ratio))
			alerte_batterie=0;
		function_UART(alerte_roulis, alerte_batterie);
 }
예제 #2
0
/** \brief main loop to run tests.
 *
 * The tests being run are described in the documentation of this file.
 *
 * \return never returns, test loop runs ad infinitum. */
int main(void) {
   uint8_t switch_mask = 0x00; // Input switches. Read hi when pressed
   uint16_t result = 0;
   SR_t shift_reg;

   /* call all of the setup_* functions */
   cli();
   setup_clocks();
   setup_LEDs();
   setup_switches(switch_mask);
   setup_SR(&shift_reg, &SR_PORT, &SR_SPI_MODULE, false);
   setup_ADC(&ADC_PORT, &ADC_SPI_MODULE, ADC_CONVST_bm, ADC_EOC_bm,
             ADC_callback);
   setup_USART_BC();
   sei();

   set_channel(MPx, 15, &shift_reg);
   set_channel(MPy, 15, &shift_reg);

   /* signal debugging */
   PORTD.DIRCLR |= PIN4_bm;
   PORTD.PIN4CTRL = PORT_OPC_PULLDOWN_gc;

   while (1)
   {
      if (ADC_ready(&adc)) {
         // get a new conversion result
         result = ADC_sample_once(&adc);
      }

      if (PORTD.IN & PIN4_bm) {
         LED_PORT.OUT = 0xFF;
      }
      else {
         LED_PORT.OUT = (uint8_t)(result >> 4);
         printf("%u ", result);
      }
   }
}