void Music_Play(const unsigned short *instrument, int instrumentSize, const struct Songs* song, int songSize){ int noteIndex=0; int i=0; int pause=0; while(1){ if(play){ pause=1-pause; resetSwitches(); } if(rewind||mode){ break; } if(lenPush&&!pause){ Timer0A_Init(song->duration[noteIndex]); SysTick_Init(402000/(song->notes[noteIndex])); noteIndex=(noteIndex+1)%songSize; } if(notePush&&!pause){ notePush=0; DAC_Out(instrument[i]); i=(i+1)%instrumentSize; } } /* //in class he mentioned something about having to layer two interrupts ontop of each other and how that can help, we may //have to do something with that. I plan on asking the TA's about it tomorrow. DAC_Out(song->notes[Time&0x1F] + instrument[Time&0x1F]); // DAC_Out(song->notes[Time&0x1F]); // DAC_Out(instrument[Time&0x1F]); Time = Time + 1; SysTick_Wait(song->duration[Time&0x1F]); */ }
// set tempo and start of the song // and initialize timer void Music_Init(void){ Song_Sel = 0; // (which note gets the beat*1000(ms/s)*60(s/min))/(beats/min) = (ms/beat) Beat = (Songs[Song_Sel].TimeSig*1000*60)/(Songs[Song_Sel].Tempo); // Changes tempo to ms per beat Timer0A_Init(&Next_Sine_Point); // Initialize Timer0A and associate function // to be executed in handler Timer0B_Init(&Next_Note); // Initialize Timer0B and associate function // to be executed in handler Current_Spot = 0; // initialize current note and current point Current_Sine_Point = 0; }
//debug code int main(void){ volatile unsigned long delay; SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOC; // activate port C delay = SYSCTL_RCGC2_R; // allow time to finish activating GPIO_PORTC_DIR_R |= 0x20; // make PC5 out (PC5 built-in LED) GPIO_PORTC_DEN_R |= 0x20; // enable digital I/O on PC5 Timer0A_Init(); // initialize timer0A (~20,000 Hz) while(1){ WaitForInterrupt(); } }
int main(void){ DisableInterrupts(); PLL_Init(); // configure for 50 MHz clock SYSCTL_RCGCGPIO_R |= 0x01; // 1) activate clock for Port A while((SYSCTL_PRGPIO_R&0x01) == 0){}; GPIO_PORTA_AMSEL_R &= ~0x38; // disable analog function GPIO_PORTA_PCTL_R &= ~0x00FFF000; // GPIO GPIO_PORTA_DIR_R |= 0x38; // make PA5-3 outputs GPIO_PORTA_AFSEL_R &= ~0x38;// disable alt func on PA5-3 GPIO_PORTA_DEN_R |= 0x38; // enable digital I/O on PA5-3 // configure PA5-3 as GPIO Timer0A_Init(5); // 200 kHz SysTick_Init(304); // 164 kHz EnableInterrupts(); while(1){ PA5 = PA5^0x20; } }
int main(void){ PLL_Init(Bus50MHz); // 50 MHz // 1) activate clock for Port F SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R5; // allow time to finish activating while((SYSCTL_PRGPIO_R&SYSCTL_PRGPIO_R5)==0){}; // 2) no need to unlock PF2 GPIO_PORTF_PCTL_R &= ~0x00000F00;// 3) configure PF2 as GPIO GPIO_PORTF_AMSEL_R &= ~0x04; // 4) disable analog function on PF2 GPIO_PORTF_DIR_R |= 0x04; // 5) make PF2 out (PF2 built-in blue LED) GPIO_PORTF_AFSEL_R &= ~0x04; // 6) disable alt funct on PF2 GPIO_PORTF_DEN_R |= 0x04; // 7) enable digital I/O on PF2 PWM0A_Init(250, 125); // initialize PWM0A, 100kHz, 50% duty // Timer0A_Init(&OutputSineWave, 3551);// initialize 440 Hz sine wave output Timer0A_Init(&OutputSineWave, 1563);// initialize 1000 Hz sine wave output while(1){ WaitForInterrupt(); } }
//debug code int main(void){ DisableInterrupts(); PLL_Init(Bus80MHz); // bus clock at 50 MHz PortF_Init(); LEDS = 0; // turn all LEDs off DAC_Init(0); Buttons_Init(); SysTick_Init(); //Timer0A_Init(&Song_PlayHandler, F20KHZ); // initialize timer0A (20,000 Hz) Timer0A_Init(&Song_PlayHandler, F16HZ); // initialize timer0A (16 Hz) EnableInterrupts(); Song_PlayInit(Prelude); Pause(); while(1){ LEDS ^= RED; for(int i = 0; i < 1000000; i += 1); } }
int main(void){ HeartBeat_Init(); DAC_Init(1024); // initialize with command: Vout = Vref Timer0A_Init(dt[0]); LCD_Init(); // Initialize RNG Random_Init(121213); // Initialize touchscreen GPIO Touch_Init(); //lenPush = 1; //for(i=0; i<50; i=i+1){ InitializeBars(); for(i=0; i<400; i=i+1){ MovingColorBars(); } for(i=0; i<400; i=i+1){ DestabilizeBars(); } for(i=0; i<350; i=i+1){ FinishBars(); } for(i=0; i<1000; i=i+1){ Random4BPPTestSprite(); } LCD_ColorFill(convertColor(0, 0, 0)); Buttons_Init(); play = 0; while(1){ if (instrument == 0){ Music_Play(Wave[0], 64, strobePtr, 35); } if (instrument == 1){ Music_Play(Trumpet[0], 32, strobePtr, 35); } if (instrument == 2){ Music_Play(Flute[0], 32, strobePtr, 35); } } }
int main(void){ int i = 0; //Score set score = 0; PLL_Init(); //Sound init DAC_Init(); Timer0A_Init(Sound_Update, 1000000/11025); // Timer0B_Init(updateXAxis, 1000000/11025); // Timer1B_Init(updateYAxis, 1000000/11025); //Input ADC_Init(); portD_Init(); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); GPIOPinTypeGPIOInput(GPIO_PORTG_BASE, (GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7)); GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2); GPIOPadConfigSet(GPIO_PORTG_BASE, (GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); SysTick_Init(50000000/400); Output_Init(); Output_Color(15); SysTick_IntEnable(); EnableInterrupts(); //Set flags gFlags = 0; HWREGBITW(&gFlags, TITLE_SCREEN) = True; //Math rand set seed while(HWREGBITW(&gFlags, SELECT_DOWN) == 0 && ((GPIO_PORTG_DATA_R & 0x80) != 0)) { } while(HWREGBITW(&gFlags, SELECT_DOWN) == 1 || ((GPIO_PORTG_DATA_R & 0x80) == 0)) { } setSeed(NVIC_ST_CURRENT_R); //Game set setGraphics(1);//the lm3s can't handle more than 2 rocks at graphics level 3. gameInit(); gameSet(0); while(1) { //Only draw to buffer when it has been output to the screen if(HWREGBITW(&gFlags, FRAME_BUFFER_READY) == False) { /*if(gameLevel == -2) { drawString(myMsgs[1], makePoint(50, 40)); while ((GPIO_PORTG_DATA_R & 0x80) != 0 && HWREGBITW(&gFlags, SELECT_DOWN) == False) { } while ((GPIO_PORTG_DATA_R & 0x80) == 0 && HWREGBITW(&gFlags, SELECT_DOWN) == True) { } //Reset game */ //Check for level completion, aka all rocks and enemies are //TODO: enemies if(HWREGBITW(&gFlags, LEVEL_COMPLETE) == True) { gameSet(++gameLevel); } //Redraw the screen from scratch. clearBuffer(); //Draw the player. if(gPlayer.status == ALIVE) { drawPlayer(makePoint((int)gPlayer.x, (int)gPlayer.y), gPlayer.angle, gPlayer.exhaustOn); } for(i = 0; i < MAX_ROCKS; i++) { if(gRocks[i].status == ALIVE) { drawRock(makePoint(gRocks[i].x, gRocks[i].y), gRocks[i].rockType, gRocks[i].rockSize); } } //Draw allied bullets. for(i = 0; i < MAX_PLAYER_BULLETS; i++) { if(gPlayerBullets[i].status == ALIVE) { drawBullet(makePoint(gPlayerBullets[i].x, gPlayerBullets[i].y)); } } //Draw enemy bullets. for(i = 0; i < MAX_ENEMY_BULLETS; i++) { if(gEnemyBullets[i].status == ALIVE) { drawBullet(makePoint(gEnemyBullets[i].x, gEnemyBullets[i].y)); } } //Draw explosions. for(i = 0; i < MAX_EXPLOSIONS; i++) { if(gExplosions[i].status == ALIVE) { drawExplosion(gExplosions[i].pos, gExplosions[i].current); } } // drawNumber(score, makePoint(2,2)); drawNumber(gameLevel, makePoint(128/2-6,2)); if(HWREGBITW(&gFlags, GAME_OVER) == True) { drawString("GAME OVER", makePoint(40, 38)); if((GPIO_PORTG_DATA_R & 0x80)) { //reset game } gameUpdate(); } else if(HWREGBITW(&gFlags, TITLE_SCREEN) == True) { drawString("ASTEROIDS", makePoint(40, 38)); gameLevel = 0; } updateXAxis(); gameUpdate(); HWREGBITW(&gFlags, FRAME_BUFFER_READY) = True; } } }
void Music_Play(const unsigned short *instrument, int instrumentSize, const struct Songs* song, int songSize){ int noteIndex=0; int i=0; int pause=0; const unsigned short *testInstr; testInstr = &Flute[0]; while(1){ if(play){ plotImage(); pause=1-pause; resetSwitches(); } if(aNote){ plotImage(); demoPtr->notes[noteIndex] = 1776; demoPtr->duration[noteIndex] = 10000; lenPush = 1; aNote = 0; } if(fNote){ plotImage(); demoPtr->notes[noteIndex] = 2237; demoPtr->duration[noteIndex] = 10000; lenPush = 1; fNote = 0; } if(bNote){ plotImage(); demoPtr->notes[noteIndex] = 1582; demoPtr->duration[noteIndex] = 10000; lenPush = 1; bNote = 0; } if(eNote){ plotImage(); demoPtr->notes[noteIndex] = 2370; lenPush = 1; eNote = 0; } if(lenPush&&!pause){ Timer0A_Init(demoPtr->duration[noteIndex]); //SysTick_Init(402000/(song->notes[noteIndex])); //SysTick_Init(402000/(furElisePtr->notes[noteIndex])); SysTick_Init(402000/(demoPtr->notes[noteIndex])); //SysTick_Init(402000/(demo1Ptr->notes[noteIndex])); noteIndex=(noteIndex+1)%(songSize); } if(notePush&&!pause){ notePush=0; DAC_Out(instrument[i]); i=(i+1)%instrumentSize; } } /* //in class he mentioned something about having to layer two interrupts ontop of each other and how that can help, we may //have to do something with that. I plan on asking the TA's about it tomorrow. DAC_Out(song->notes[Time&0x1F] + instrument[Time&0x1F]); // DAC_Out(song->notes[Time&0x1F]); // DAC_Out(instrument[Time&0x1F]); Time = Time + 1; SysTick_Wait(song->duration[Time&0x1F]); */ }