mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 01:11:10 +03:00
buzzer: C implementation; C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
@ -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]
|
||||
|
||||
|
Reference in New Issue
Block a user