void update_puck_angle () { float PT_angles[7] = {-0.96, -0.48, 0, 3.14, 0, 0.48, 0.96}; //{Wide Left, left spike, left front, back, right front, right spike, wide right} float PT_values[7] = {0,0,0,0,0,0,0}; float PT_weighted[7] = {0,0,0,0,0,0,0}; int total = 0; int i = 0; ADC0(); PT_values[0] = ADC; ADC1(); PT_values[1] = ADC; ADC4(); PT_values[2] = ADC; ADC5(); PT_values[3] = ADC; ADC6(); PT_values[4] = ADC; ADC7(); PT_values[5] = ADC; ADC8(); PT_values[6] = ADC; m_usb_tx_string("\n"); for(i = 2; i<6; i++){ if(PT_values[i]<PT_THRESHOLD){ PT_values[i] = 0; } } puck_angle = 0; total = 0; for(i = 0; i<7; i++){ puck_angle += PT_values[i]*PT_angles[i]; total += PT_values[i]; m_usb_tx_int(PT_values[i]); m_usb_tx_string("\t"); } puck_angle = puck_angle/total; m_usb_tx_int(total); m_usb_tx_string("\t"); m_usb_tx_int((int)(puck_angle * 100)); if(total > 5){ see_puck = 1; } else { see_puck = 0; } }
main() { //make these pins outputs DDRC|=((1<<DDC2)|(1<<DDC3)|(1<<DDC4)|(1<<DDC5)); DDRD|=(1<<DDD0); //USART_Init(); //uint8_t data0, data1; ADC_Init(); while(1) { /* */ if(PINB&(1<<PB3))//PD0 high****************** manual mode { PORTC&=(~((1<<PC2)|(1<<PC3)|(1<<PC4)|(1<<PC5))); PORTD&=(~(1<<PD0)); if(PINB&(1<<PB4)) //PB4 high { PORTC&=(~(1<<PC2)); PORTD&=(~(1<<PD0)); PORTC|=((1<<PC4)|(1<<PC3)|(1<<PC5)); // = ***************open window _delay_ms(100); PORTC&=(~((1<<PC2)|(1<<PC3)|(1<<PC4)|(1<<PC5))); PORTD&=(~(1<<PD0)); } if(PINB&(1<<PB5)) //PB5 high { PORTC&=(~((1<<PC3)|(1<<PC5))); PORTD|=(1<<PD0); PORTC|=((1<<PC2)|(1<<PC4)); _delay_ms(100); PORTC&=(~((1<<PC2)|(1<<PC3)|(1<<PC4)|(1<<PC5))); PORTD&=(~(1<<PD0)); } //break; } //while(~(PINB&(1<<PB3))) //k****************automatic mode else { //while(1) //{ /* _delay_ms(100); ADMUX=((1<<REFS0)|(1<<ADLAR)|(0<<MUX0)); _delay_ms(40); data0=ADC_Read(); _delay_ms(100); ADMUX=((1<<REFS0)|(1<<ADLAR)|(1<<MUX0)); _delay_ms(40); data1=ADC_Read(); */ while(ADC0()<(ADC1()-0x15)) { //USART_putstring("ADC0 low"); //USARTWriteChar(); PORTC&=(~(1<<PC2)); PORTD&=(~(1<<PD0)); PORTC|=((1<<PC4)|(1<<PC3)|(1<<PC5)); // = ***************open window break; // } while(ADC0()>(ADC1()+0x15)) //CLOSE WINDOW { // USART_putstring("ADC0 HIGH\r\n"); PORTC&=(~((1<<PC3)|(1<<PC5))); PORTD|=(1<<PD0); PORTC|=((1<<PC2)|(1<<PC4)); break; } while(((ADC1()-0X15)<ADC0())&(ADC0()<(ADC1()+0x15))) { PORTC&=(~((1<<PC2)|(1<<PC3)|(1<<PC4)|(1<<PC5))); PORTD&=(~(1<<PD0)); break; } // break; } } }