int main(void) { unsigned char IR[12]; // 0 -> avcc=ref init_hw(); while (1) { if (i2c_get_received_data(rec_buf)){ if (rec_buf[0] == SET_COLOR){ RGB[0] = rec_buf[1]; RGB[1] = rec_buf[2]; RGB[2] = rec_buf[3]; } if(rec_buf[0] == READ_IR ){ out_buf[0]= IR[0]; out_buf[1]= IR[1]; out_buf[2]= IR[2]; out_buf[3]= IR[3]; i2c_send_data(out_buf); } } // Update PWMs set_color (RED, RGB[0]); set_color (GREEN, RGB[1]); set_color (BLUE, RGB[2]); Read_IR((unsigned short*)IR, 0x80); _delay_ms(IR_DELAY); } return(0); // avoid gcc warning }
void check_i2c_interface(void){ if (i2c_get_received_data(i2c_buf)){ if (i2c_buf[0]=='i'){ if (i2c_buf[1]=='=' && i2c_buf[2]!='\0'){ set_val[0]=atoi(&i2c_buf[2]); if(set_val[0]>I_MAX){ set_val[0]=I_MAX; } if(set_val[0]<0){ set_val[0]=0; } i2c_send_data("ok"); }else{ int_to_ascii(measured_val[0],i2c_buf,2,0); strcat(i2c_buf,"A"); i2c_send_data(i2c_buf); } }else if (i2c_buf[0]=='s'){ store_permanent(); i2c_send_data("ok"); }else if (i2c_buf[0]=='u'){ if (i2c_buf[1]=='=' && i2c_buf[2]!='\0'){ set_val[1]=atoi(&i2c_buf[2]); if(set_val[1]>U_MAX){ set_val[1]=U_MAX; } if(set_val[1]<0){ set_val[1]=0; } i2c_send_data("ok"); }else{ int_to_ascii(measured_val[1],i2c_buf,1,0); strcat(i2c_buf,"V"); i2c_send_data(i2c_buf); } }else{ i2c_send_data("err"); } } }