buzzer: C implementation; C++ wraps C

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson
2016-10-28 16:47:01 -06:00
parent f623414c04
commit 7b9fbd8738
16 changed files with 461 additions and 154 deletions

View File

@ -31,18 +31,21 @@
int
main(int argc, char **argv) {
//! [Interesting]
int chord[] = { DO, RE, MI, FA, SOL, LA, SI, DO, SI };
int chord[] = { BUZZER_DO, BUZZER_RE, BUZZER_MI,
BUZZER_FA, BUZZER_SOL, BUZZER_LA,
BUZZER_SI };
// create Buzzer instance
upm::Buzzer* sound = new upm::Buzzer(5);
// print sensor name
std::cout << sound->name() << std::endl;
// play sound (DO, RE, MI, etc...), pausing for 0.1 seconds between notes
for (int chord_ind = 0; chord_ind < 7; chord_ind++) {
// play each note for one second
std::cout << sound->playSound(chord[chord_ind], 1000000) << std::endl;
usleep(100000);
// play each sound (DO, RE, MI, etc...) for .5 seconds, pausing
// for 0.1 seconds between notes
for (int chord_ind = 0; chord_ind < 7; chord_ind++)
{
std::cout << sound->playSound(chord[chord_ind], 500000) << std::endl;
upm_delay_ms(100);
}
//! [Interesting]