#include <unistd.h>
#include <iostream>
#include <signal.h>
-
#include "buzzer.h"
-int running = 0;
-
-void
-sig_handler(int signo)
-{
- printf("got signal\n");
- if (signo == SIGINT) {
- printf("exiting application\n");
- running = 1;
- }
-}
int
main(int argc, char **argv) {
std::cout << sound->name() << std::endl;
// play sound (DO, RE, ME, etc...)
- signal(SIGINT, sig_handler);
-
- while (!running) {
- for (int chord_ind = 0; chord_ind < 9; chord_ind++) {
- std::cout << sound->playSound(chord[chord_ind]) << std::endl;
- usleep(1000);
- }
+ for (int chord_ind = 0; chord_ind < 7; chord_ind++) {
+ // play one second for each chord
+ std::cout << sound->playSound(chord[chord_ind], 1000000) << std::endl;
+ usleep(100000);
}
//! [Interesting]
m_name = "Buzzer";
}
-int Buzzer::playSound (int note) {
+int Buzzer::playSound (int note, int delay) {
maa_pwm_enable (m_pwm_context, 1);
maa_pwm_period_us (m_pwm_context, note);
- maa_pwm_write (m_pwm_context, 50.0);
- usleep (10000);
+ maa_pwm_pulsewidth_us (m_pwm_context, note / 2);
+ usleep (delay);
maa_pwm_enable (m_pwm_context, 0);
- return 0;
+ return note;
}
Buzzer::~Buzzer() {
#include <string>
#include <maa/pwm.h>
-#define DO 3830000 // 261 Hz
-#define RE 3400000 // 294 Hz
-#define MI 3038000 // 329 Hz
-#define FA 2864000 // 349 Hz
-#define SOL 2550000 // 392 Hz
-#define LA 2272000 // 440 Hz
-#define SI 2028000 // 493 Hz
+#define DO 3300 // 261 Hz 3830
+#define RE 2930 // 294 Hz
+#define MI 2600 // 329 Hz
+#define FA 2460 // 349 Hz
+#define SOL 2190 // 392 Hz
+#define LA 1960 // 440 Hz
+#define SI 1750 // 493 Hz
namespace upm {
*
* This file defines the Buzzer C++ interface for libbuzzer
*
- * @snippet es08a.cxx Interesting
+ * @snippet buzzer-sound.cxx Interesting
*
*/
class Buzzer {
* Play chords.
*
* @param note chords (DO, RE, ME, etc...)
+ * @param delay time in microsec for playing the sound
*/
- int playSound (int note);
+ int playSound (int note, int delay);
/**
* Return name of the component