Uploaded by Thee Surge

Sound Output

advertisement
// Sound Output
int counter = 0;
int note = 0;
int TickFct_SoundOutput(int state) {
// WHEN NOTE = 0 IT MAY MEAN SONG IS FINISHED
switch (state) { // State Transitions
case SO_init:
state = SO_SoundOn;
break;
case SO_SoundOn:
if(counter >= song1_time[note]) {
state = SO_SoundOff;
note++;
counter = 0;
note = note % 20;
}
break;
case SO_SoundOff:
state = SO_SoundOn;
counter++;
counter = counter % 4;
break;
}
switch (state) { // State Actions
case SO_SoundOn:
tone(8, song1[note], periodSoundOutput* song1_time[note]);
counter++;
break;
case SO_SoundOff:
noTone(8);
break;
}
return state;
}
Download