int16_t get_red_sensor(){ int16_t meas[RGB_MEAS_COUNT]; int16_t red_val; //printf("R: "); for(uint8_t meas_count=0; meas_count<RGB_MEAS_COUNT; meas_count++){ ADCA.CH0.CTRL |= ADC_CH_START_bm; while (ADCA.CH0.INTFLAGS==0){}; // wait for measurement to complete meas[meas_count] = ((((int16_t)(ADCA.CH0.RESH))<<8)|((int16_t)ADCA.CH0.RESL))>>4; ADCA.CH0.INTFLAGS=1; // clear the complete flag //printf("%6d ", meas[meas_count]); } //printf("\r\n"); red_val=meas_find_median(&meas[2], RGB_MEAS_COUNT-2); return red_val; }
int16_t get_green_sensor() { int16_t meas[RGB_MEAS_COUNT]; int16_t green_val; for(uint8_t meas_count=0; meas_count<RGB_MEAS_COUNT; meas_count++) { ADCA.CH1.CTRL |= ADC_CH_START_bm; while (ADCA.CH1.INTFLAGS==0){}; // wait for measurement to complete meas[meas_count] = ((((int16_t)(ADCA.CH1.RESH))<<8)|((int16_t)ADCA.CH1.RESL))>>4; ADCA.CH1.INTFLAGS=1; // clear the complete flag } green_val=meas_find_median(&meas[2], RGB_MEAS_COUNT-2); //printf("%d\t", green_val); return green_val; }