int main (void) { int start_position = 42; //zmienna pomocniczne do sterowania serwami __disable_irq(); temp1=temp2=start_position; Clock_Initialize(); GPIO_Initialize(); Timer1_init(); Timer2_init(); __enable_irq(); FPTB->PDOR =0; NVIC->ICER[0]|=(1UL<<(30%32))|(1UL<<(31%32)); NVIC->ISER[0]|=(1UL<<(30%32))|(1UL<<(31%32)); while(1){ if( !(FPTB->PDIR&(1<<0))){ prawo(700); } if(!(FPTB->PDIR&(1<<1))){ lewo(700); } } }
int main(int argc, char* argv[]) { volatile int16_t note = -1; Output_init(); ADC_init(); // Initialize the ADC Timer2_init(); // Initialize Tim2 while (1) { if(index == max_index){//we've finished the song... start over! index = 0; } // Check if a data array is ready for FFT processing if(arrayComplete==1){ arrayComplete = 0; // Reset arrayComplete // Process the array that completed! if(array1Complete == 1){ int16_t out = fix_fftr(dataArray1,10,0); note = getNote(dataArray1); array1Complete = 0;//mark array as available to re-fill } else if(array2Complete == 1) { int16_t out = fix_fftr(dataArray2,10,0); note = getNote(dataArray2); array2Complete = 0;//mark array as available to re-fill } int16_t selectedNote = processNote(note); switch(selectedNote) { case -2: // Pause (actually play a frequency so high that no one but dogs can hear it) TIM2->ARR = 1000000/40000; // Set frequency (40 kHz) break; case -1: // Continue playing the same note break; case 0: // Generate C4 262 Hz TIM2->ARR = 1000000/262/4; // Set frequency break; case 1: // Generate C#4 277 Hz TIM2->ARR = 1000000/277/4; // Set frequency break; case 2: // Generate D4 294 Hz TIM2->ARR = 1000000/294/4; // Set frequency break; case 3: // Generate D#4 311 Hz TIM2->ARR = 1000000/311/4; // Set frequency break; case 4: // Generate E4 330 Hz TIM2->ARR = 1000000/330/4; // Set frequency break; case 5: // Generate F4 349 Hz TIM2->ARR = 1000000/349/4; // Set frequency break; case 6: // Generate F#4 370 Hz TIM2->ARR = 1000000/370/4; // Set frequency break; case 7: // Generate G4 392 Hz TIM2->ARR = 1000000/392/4; // Set frequency break; case 8: // Generate G#4 415 Hz TIM2->ARR = 1000000/415/4; // Set frequency break; case 9: // Generate A4 440 Hz TIM2->ARR = 1000000/440/4; // Set frequency break; case 10: // Generate A# 466 Hz TIM2->ARR = 1000000/466/4; // Set frequency break; case 11: // Generate B4 494 Hz TIM2->ARR = 1000000/494/4; // Set frequency break; case 12: // Generate C5 523 Hz TIM2->ARR = 1000000/523/4; // Set frequency break; case 13: // Generate C#6 554 Hz TIM2->ARR = 1000000/554/4; // Set frequency break; default: break; } } } }