I am new to arduboy, I wanted to add some music to it, and this is the small code I made.
It didn’t work. What I am missing?
The speaker is not on pin 11
Pinouts here:
For the Arduboy, instead of using Arduino tone(), it’s better to use one of the a Arduboy targeted methods to generate sound, such as the Arduboy2 BeepPin classes, ArduboyTones, ArduboyPlaytune, ATMlib, ArdVoice.
For what you’ve currently written, ArduboyTones would probably be the most suitable.
Also note that none of functions you’re using take floats as arguments. You should change the values to integers.
Here’s my attempt at converting your sketch to use the ArduboyTones library. (I added a 2 second delay at the end of loop(), before the sequence repeats.)
Some of the tones are too low for the Arduboy’s speaker and most of the durations are very short (they are in milliseconds).
#include <Arduboy2.h>
#include <ArduboyTones.h>
Arduboy2 arduboy;
ArduboyTones sound(arduboy.audio.enabled);
const uint16_t midi[] PROGMEM = {
184,410,
NOTE_REST,45,
277,9,
NOTE_REST,11,
38,9,
NOTE_REST,1,
41,9,
NOTE_REST,1,
1479,9,
NOTE_REST,1,
415,17,
NOTE_REST,2,
1244,17,
NOTE_REST,128,
146,17,
NOTE_REST,2,
TONES_END };
void setup() {
arduboy.begin();
}
void loop() {
sound.tones(midi);
arduboy.delayShort(2000);
}
Thanks for the help!
You don’t need to call arduboy.clear()
after arduboy.begin()
by the way.
Actually, you do if you intend to write to a blank screen. Otherwise, the boot logo will remain in the screen buffer. As the sketch stands now, there’s no call to arduboy.display()
so it currently makes no difference.
Oops. I meant to add that part, but I must have got distracted in the middle of sending and forgot, or it got lost when I restarted my browser or something. Busy day.