Boot Logo Tones

So I wanted to test a simple addition to my Arduboy. During the bootLogo, I added a simple object that adds tones to this screen. Simply add the ArduboyTones.h library in the core asset.

Arduboy2.h add #include ArduboyTones.h

Arduboy2.cpp goto bootLogoShell function and add
extern ArduboyTones systemtones;
then simply place systemtone.tone(800,300); between the digitalWriteRGB commands, changing the note for each one.

I know its just a hack, but by adding only 32 bytes to a project that already uses the Tones library, this didn’t seem to be much overhead for something like this.

3 Likes

But I can’t add it to the Arduboy2 library. By including ArduboyTones.h it takes over a timer interrupt, making it impossible to use other sound libraries that also use that timer, such as ArduboyPlaytune. This is the reason that the Arduboy2 library doesn’t include any sound generating functions itself.

If a sketch wants to generate sound during the boot logo sequence, a good way to do it would be to copy the library code for the bootLogoShell() and support functions then use it to make a local function with modifications. You would then use boot() instead of begin() and manually call all the system functions afterwards, but use the custom boot logo function.

Here’s an example:

#include <Arduboy2.h>
#include <ab_logo.c>
#include <ArduboyTones.h>

Arduboy2 arduboy;
ArduboyTones sound(arduboy.audio.enabled);

void setup() {
  arduboy.boot();
  arduboy.blank(); // blank the display
  arduboy.flashlight(); // light the RGB LED and screen if UP button is being held.
  arduboy.systemButtons();
  arduboy.audio.begin();
  bootLogoWithSound();
  // wait for all buttons to be released
  do {
    arduboy.delayShort(50);
  } while (arduboy.buttonsState());
}

void loop() {
}

void bootLogoWithSound()
{
  sound.tone(NOTE_C5, 500);
  arduboy.digitalWriteRGB(RED_LED, RGB_ON);

  for (int16_t y = -18; y <= 24; y++) {
    if (arduboy.pressed(RIGHT_BUTTON)) {
      arduboy.digitalWriteRGB(RGB_OFF, RGB_OFF, RGB_OFF); // all LEDs off
      return;
    }

    if (y == -4) {
      sound.tone(NOTE_G5, 500);
      arduboy.digitalWriteRGB(RED_LED, RGB_OFF);    // red LED off
      arduboy.digitalWriteRGB(GREEN_LED, RGB_ON);   // green LED on
    }
    else if (y == 24) {
      sound.tone(NOTE_C6, 500);
      arduboy.digitalWriteRGB(GREEN_LED, RGB_OFF);  // green LED off
      arduboy.digitalWriteRGB(BLUE_LED, RGB_ON);    // blue LED on
    }

    arduboy.clear();
    arduboy.drawBitmap(20, y, arduboy_logo, 88, 16); // call the function that actually draws the logo
    arduboy.display();
    arduboy.delayShort(27);
    // longer delay post boot, we put it inside the loop to
    // save the flash calling clear/delay again outside the loop
    if (y==-16) {
      arduboy.delayShort(250);
    }
  }

  arduboy.delayShort(700);
  arduboy.digitalWriteRGB(BLUE_LED, RGB_OFF);

  arduboy.bootLogoExtra();
}