User manual
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
465
Library Example
The example is a simple demonstration of how to use the Sound Library for playing tones on a piezo speaker.
Copy Code To Clipboard
program Sound
sub procedure Tone1()
Sound_Play(659, 250) ‘ Frequency = 659Hz, duration = 250ms
end sub
sub procedure Tone2()
Sound_Play(698, 250) ‘ Frequency = 698Hz, duration = 250ms
end sub
sub procedure Tone3()
Sound_Play(784, 250) ‘ Frequency = 784Hz, duration = 250ms
end sub
sub procedure Melody() ‘ Plays the melody “Yellow house”
Tone1() Tone2() Tone3() Tone3()
Tone1() Tone2() Tone3() Tone3()
Tone1() Tone2() Tone3()
Tone1() Tone2() Tone3() Tone3()
Tone1() Tone2() Tone3()
Tone3() Tone3() Tone2() Tone2() Tone1()
end sub
sub procedure ToneA() ‘ Tones used in Melody2 function
Sound_Play( 880, 50)
end sub
sub procedure ToneC()
Sound_Play(1046, 50)
end sub
sub procedure ToneE()
Sound_Play(1318, 50)
end sub
sub procedure Melody2() ‘ Plays Melody2
dim counter as byte
for counter = 9 to 1 step-1
ToneA()
ToneC()
ToneE()
next counter
end sub
main:
ADPCFG = 0xFFFF ‘ Congure AN pins as digital I/O
TRISB = 0xF8 ‘ Congure RB7..RB3 as input
Sound_Init(PORTD, 3)