Page 266 - ARM Based Microcontroller Projects Using MBED
P. 266
252 8. INTERMEDIATE LEVEL PROJECTS
// Play the melody
//
while(1) // Do forever
{
for(int k = 0; k < MaxNotes; k++) // Do for all notes
{
pwm.period(Period[k]);
pwm.pulsewidth(DutyCycle[k]); // 50% Duty Cycle
wait(Durations[k]); // In seconds
pwm.pulsewidth(0.0); // Stop PWM
wait_ms(100); // 100ms Note gap
}
wait(3.0); // Repeat after 3s
}
}
FIG. 8.121, CONT’D
8.36.2 Aim
The aim of this project is to show how PWM can be programmed to create a simple elec-
tronic organ with one octave.
8.36.3 Block Diagram
The block diagram of the project is shown in Fig. 8.122.
FIG. 8.122 Block diagram of the project.