Datasheet
Library Example
The example is a simple demonstration of how to use the Sound Library for playing
tones on a piezo speaker.
program Sound
' Sound connections
dim Sound_Play_Pin as sbit at PORTC.B3
dim Sound_Play_Pin_direction as sbit at DDRC.B3
' End Sound connections
sub procedure Tone1
Sound_Play(500, 200) ' Frequency = 500Hz, Duration = 200ms
end sub
sub procedure Tone2
Sound_Play(555, 200) ' Frequency = 555Hz, Duration = 200ms
end sub
sub procedure Tone3
Sound_Play(625, 200) ' Frequency = 625Hz, Duration = 200ms
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(1250, 20)
end sub
sub procedure ToneC
Sound_Play(1450, 20)
end sub
sub procedure ToneE
Sound_Play(1650, 80)
end sub
sub procedure Melody2 ' Plays Melody2
dim counter as byte
for counter = 9 to 1 step -1
359
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6