int MATLAB_test(int count, ...) { char rx_buffer; //see wikipedia article on variadic functions****** va_list ap; int array[count]; va_start(ap, count); for (int j= 0; j < count; j++) { array[j] = va_arg(ap, int); } va_end(ap); //************* //char rx_buffer; while(!m_usb_rx_available()); //wait for an indication from the computer rx_buffer = m_usb_rx_char(); //grab the computer packet m_usb_rx_flush(); //clear buffer if(rx_buffer == 1) { //computer wants ir buffer //write ir buffer as concatenated hex: i.e. f0f1f4f5 for (int i = 0; i < count; i++) { m_usb_tx_uint(array[i]); m_usb_tx_char('\t'); } m_usb_tx_char('\n'); //MATLAB serial command reads 1 line at a time } }
int main(void) { unsigned int value; m_usb_init(); while(!m_usb_isconnected()); // wait for a connection while(1) { if(m_usb_rx_available()) { value = m_usb_rx_char(); m_usb_tx_uint(value); } } }
int main(void) { unsigned long runtime = 0; m_clockdivide(0); // 16 MHz OCR1B = 521; // initialize output compare register (interrupt every 521 cycles) set(DDRB,6); // set B6 as output (output compare pin) set(DDRB,4); // set B4 as output (green LED for data synchronization) set(PORTB,4); // turn on green LED on B4 set(DDRF,0); // set F0 as output set(DDRF,1); // set F1 as output set(DDRB,1); // set B1 as output m_usb_init(); while(!m_usb_isconnected()){ m_green(ON); } m_green(OFF); set(DDRB,2); while(!m_usb_rx_available()); // wait for runtime argument from Python script m_wait(5); while(m_usb_rx_available()){ runtime = runtime * 10 + (m_usb_rx_char() - '0'); // build number of seconds } runtime = runtime * 1000000; // convert to microseconds clear(PORTF,0); // S0 clear(PORTF,1); // S1 clear(PORTB,1); // S2 m_wait(10); if(!m_imu_init(0,1)){ m_red(ON); // RED LED turns on if there's a problem m_usb_tx_string("IMU0 could not connect"); } /* set(PORTF,0); m_wait(10); if(!m_imu_init(0,1)){ m_red(ON); // RED LED turns on if there's a problem m_usb_tx_string("IMU1 could not connect"); } clear(PORTF,0); set(PORTF,1); m_wait(10); if(!m_imu_init(0,1)){ m_red(ON); // RED LED turns on if there's a problem m_usb_tx_string("IMU2 could not connect"); } set(PORTF,0); m_wait(10); if(!m_imu_init(0,1)){ m_red(ON); // RED LED turns on if there's a problem m_usb_tx_string("IMU3 could not connect"); } set(PORTB,1); clear(PORTF,0); clear(PORTF,1); m_wait(10); if(!m_imu_init(0,1)){ m_red(ON); // RED LED turns on if there's a problem m_usb_tx_string("IMU4 could not connect"); } set(PORTF,0); m_wait(10); if(!m_imu_init(0,1)){ m_red(ON); // RED LED turns on if there's a problem m_usb_tx_string("IMU5 could not connect"); } */ //calibrate(0); //calibrate(1); //calibrate(2); //calibrate(3); //calibrate(4); //calibrate(5); // Initialize Timer 1 output compare interrupt set(TIMSK1,OCIE1B); set(TCCR1B,CS12); clear(TCCR1B,CS11); set(TCCR1B,CS10); clear(TCCR1B,WGM13); set(TCCR1B,WGM12); clear(TCCR1A,WGM11); clear(TCCR1A,WGM10); clear(TCCR1A,COM1B1); set(TCCR1A,COM1B0); // Initialize Timer 1 overflow interrupt set(TIMSK1,TOIE1); // Initialize Timer 3 overflow interrupt overflow = 0; set(TIMSK3,TOIE3); clear(TCCR3B,CS32); clear(TCCR3B,CS31); set(TCCR3B,CS30); sei(); // enable global interrupts clear(PORTB,4); // turn off green LED --> signal to camera while(overflow * 4096 < runtime){ m_green(TOGGLE); } m_usb_tx_string(" "); m_green(OFF); //cli(); while(1); }
int main(void) { init(); // Run Timer Initializacion Code m_bus_init(); m_usb_init(); // Initialize the USB connection. m_rf_open(1, 0x15, 3); set(DDRB, 0); set(DDRB, 1); set(DDRB, 2); set(DDRB, 3); set(DDRB, 7); set(DDRD, 3); set(DDRD, 4); set(DDRD, 5); set(DDRD, 6); set(DDRD, 7); //while(!m_usb_isconnected()); // wait for a connection while(1){ if(m_usb_rx_available()) { input = m_usb_rx_char(); //m_usb_tx_int(input); m_usb_tx_string(" "); if (input == 119) { OCR3A = OCR3A - 1; } //if (input == 115) { // OCR3A = OCR3A + 1; //} //if (input == 105) { // OCR0A = OCR0A - 1; //} if (input == 107) { OCR0A = OCR0A + 1; } if (input == 105) { m_red(TOGGLE); //des_freq = 100; OCR3A = (float)62500/des_freq; duration = 100; flag_2 = 1; flag = 0; ; } if (input == 115) { des_freq += 10; } m_usb_tx_int(des_freq); } if (flag) { m_red(TOGGLE); m_rf_read(commands,3); des_freq = *(int*)&commands[0]; des_freq /= 10; // Measured: 130 is 60 Hz. 20 is 370 Hz. THIS IS INT. OCR3A = 130 - (float)(des_freq - 60)/(float)2.8; duration = commands[2]; flag_2 = 1; flag = 0; } // Max Sound duration is 255 centiseconds, which is 2.55 sec. if (flag_2) { // TCNT0 = 0; conta = 0; m_green(ON); set(DDRB, 6); clear(PORTD, 4); flag_2 = 0; } if (conta == (4*duration)) { m_green(OFF); clear(DDRB, 6); clear(PORTB, 6); set(PORTD, 4); } //if (TCNT0 == OCR0A) { if (check(TIFR0, OCF0A)){ conta += 1; set(TIFR0,OCF0A); } /* if (check(ADCSRA,ADIF)) { set(ADCSRA, ADIF); if (ADC>100) { set(PORTB, 0); } else{ clear(PORTB, 0); } if (ADC>200) { set(PORTB, 1); } else{ clear(PORTB, 1); } if (ADC>300) { set(PORTB, 2); } else{ clear(PORTB, 2); } if (ADC>400) { set(PORTB, 3); } else{ clear(PORTB, 3); } if (ADC>500) { set(PORTB, 7); } else{ clear(PORTB, 7); } if (ADC>600) { set(PORTD, 3); } else{ clear(PORTD, 3); } if (ADC>700) { set(PORTD, 4); } else{ clear(PORTD, 4); } if (ADC>800) { set(PORTD, 5); } else{ clear(PORTD, 5); } if (ADC>900) { set(PORTD, 6); } else{ clear(PORTD, 6); } if (ADC>1000) { set(PORTD, 7); } else{ clear(PORTD, 7); } } */ //m_usb_tx_string("\r"); // Carriage Return //m_usb_tx_uint(ADC); //m_usb_tx_string("\r"); // Carriage Return //m_usb_tx_hex(commands[0]); //m_usb_tx_uint(des_freq); //m_usb_tx_string(" "); //m_usb_tx_char(commands[2]); //m_usb_tx_string(" OCR3A: "); //m_usb_tx_uint(OCR3A); //m_usb_tx_string(" "); // Measured: 0x81 (129, we can use 130) is 60 Hz. 46 (70) is 110 Hz. // I get values from 60 to 110 // Do only every time the Timer Overflows //while(!check(TIFR3, OCF3A)); if (check(TIFR3, OCF3A)) { if(indx<255){ indx += 1; } else{ indx = 0; } //Define new value for Duty Cycle According to Sine Table OCR1B = sinewave_data[indx]; set(TIFR3, OCF3A); //Clear Flag } // Display information for the SCREEN. /* m_usb_tx_string("ADC Input Value: "); // m_usb_tx_uint(ADC); //transmit over USB m_usb_tx_string(" DIP Switch Inputs:"); // //m_usb_tx_uint(check(PIND,4)); //m_usb_tx_string(" "); m_usb_tx_uint(check(PIND,5)); //m_usb_tx_string(" "); m_usb_tx_uint(check(PIND,6)); //m_usb_tx_string(" "); m_usb_tx_uint(check(PIND,7)); m_usb_tx_string(" "); m_usb_tx_uint((check(PIND, 4) * 1 + check(PIND, 5) * 2 + check(PIND, 6) * 4 + check(PIND, 7) * 8 + 1)); m_usb_tx_string(" Duty Cycle "); m_usb_tx_uint(((OCR1A - OCR1B)/OCR1A)*100); m_usb_tx_string("\r"); // Carriage Return //m_usb_tx_string("\n"); // Enter //m_usb_tx_string("\f"); // Form Feed //m_usb_tx_string("\f"); // Tab //m_usb_tx_string("\v"); // Vertical Tab */ } return 0; /* never reached */ }