SPC  Version 0.9.5
 All Files Functions Groups Pages
ex_Twinkle.spc

This is an example of how to use the DAC1Mode, DAC1Frequency, and DAC1Voltage system constants. It is also an example of how to use the Wait function.

void PlayNoteStacato(int note, int dur)
{
DAC1Frequency = note;
DAC1Voltage = 1023;
Wait(7*dur/8);
Wait(dur/8);
}
void PlayNoteLagato(int note, int dur)
{
DAC1Frequency = note;
DAC1Voltage = 1023;
Wait(dur);
}
void TwinkleA()
{
PlayNoteStacato(TONE_C3, NOTE_QUARTER);
PlayNoteStacato(TONE_C3, NOTE_QUARTER);
PlayNoteStacato(TONE_G3, NOTE_QUARTER);
PlayNoteStacato(TONE_G3, NOTE_QUARTER);
PlayNoteStacato(TONE_A3, NOTE_QUARTER);
PlayNoteStacato(TONE_A3, NOTE_QUARTER);
PlayNoteStacato(TONE_G3, NOTE_HALF);
PlayNoteStacato(TONE_F3, NOTE_QUARTER);
PlayNoteStacato(TONE_F3, NOTE_QUARTER);
PlayNoteStacato(TONE_E3, NOTE_QUARTER);
PlayNoteStacato(TONE_E3, NOTE_QUARTER);
PlayNoteStacato(TONE_D3, NOTE_QUARTER);
PlayNoteStacato(TONE_D3, NOTE_QUARTER);
PlayNoteStacato(TONE_C3, NOTE_HALF);
}
void TwinkleB()
{
PlayNoteStacato(TONE_G3, NOTE_QUARTER);
PlayNoteStacato(TONE_G3, NOTE_QUARTER);
PlayNoteStacato(TONE_F3, NOTE_QUARTER);
PlayNoteStacato(TONE_F3, NOTE_QUARTER);
PlayNoteStacato(TONE_E3, NOTE_QUARTER);
PlayNoteStacato(TONE_E3, NOTE_QUARTER);
PlayNoteStacato(TONE_D3, NOTE_HALF);
}
task main()
{
int A0;
// Set up Analog 1 output to output a square wave
// Sample Analog input A0 every 1/10 second
// and output value
while(true)
{
TwinkleA();
TwinkleB();
TwinkleB();
TwinkleA();
}
}