I have the NyBoard V2. I am able to compile and upload the testBuzzer module. It makes sounds, but the beeps sound more like alarm buzzers and the meow sounds like an electronic screech. Any tips on how to adjust these sounds?
I tried the WriteInstinct module (and set the version in Instict.h to "#define NyBoard_V0_2"), but got the same result.
Until I have the passive buzzer I commented out all but battery low notification.
Hi,
In OpenCat.h, you can find two function for sound
void beep(int8_t note, float duration = 10, int pause = 0, byte repeat = 1 ) { if (note == 0) {//rest note analogWrite(BUZZER, 0); delay(duration); return; } int freq = 220 * pow(1.059463, note - 1); // 1.059463 comes from https://en.wikipedia.org/wiki/Twelfth_root_of_two float period = 1000000.0 / freq; for (byte r = 0; r < repeat; r++) { for (float t = 0; t < duration * 1000; t += period) { analogWrite(BUZZER, 150); // Almost any value can be used except 0 and 255 // experiment to get the best tone delayMicroseconds(period / 2); // rise for half period analogWrite(BUZZER, 0); // 0 turns it off delayMicroseconds(period / 2); // down for half period } delay(pause); } } void playMelody(int start) { byte len = (byte)EEPROM.read(start) / 2; for (int i = 0; i < len; i++) beep(EEPROM.read(start - 1 - i), 1000 / EEPROM.read(start - 1 - len - i), 100); } void meow(int repeat = 0, int pause = 200, int startF = 50, int endF = 200, int increment = 5) { for (int r = 0; r < repeat + 1; r++) { for (int amp = startF; amp <= endF; amp += increment) { analogWrite(BUZZER, amp); delay(15); // wait for 15 milliseconds to allow the buzzer to vibrate } delay(100 + 500 / increment); analogWrite(BUZZER, 0); if (repeat)delay(pause); } }
You can play with the parameters for the functions.
Note that the meow and musical tone are kind of mutual exclusive. It's better to use an active buzzer to generate meow, and a passive buzzer to generate musical tone. On NyBoard, I'm using an active buzzer, so the music tone is less accurate. You could attach a passive buzzer on the unused pins. I think it's around $2 on eBay.