Gift Singer - Chiptune Music Box

I was able to dig up my old Fritzing files. This was done back in 2018 so it was pretty early on in my EE dabbling.

This was a little Arduino project where I built digital music boxes for my girlfriend at the time (now my wife).

The basic design was an Arduino Uno with a battery and a button. I fit them inside of little boxes with designs on the top to match the theme of the music box’s music. When you press the top of the box, the button is pressed and starts playing one of the music files using the speaker. I programmed each one to have a selection of songs from the boxes. All in chiptune style. I used miditonesV1.6 to convert midi files into the PWM signals needed to make the music.

The playtune header file is located on github: arduino-playtune/Playtune.h at master · LenShustek/arduino-playtune · GitHub

#include <Playtune.h>

const byte PROGMEM score [] = {} // Omitted the actual bytes since it's huge
const byte PROGMEM score2 [] = {} // Omitted the actual bytes since it's huge
const byte PROGMEM score3 [] = {} // Omitted the actual bytes since it's huge
const byte PROGMEM score4 [] = {} // Omitted the actual bytes since it's huge
const byte PROGMEM score5 [] = {} // Omitted the actual bytes since it's huge

Playtune pt;
int buttonPin = 9;
int LEDPin1   = A0;
int LEDPin2   = A2;
bool play = true;
unsigned long buttonTime = millis();
unsigned long debounce = 250;

int song = 0;

void setup() {
  pt.tune_initchan (10);
  pt.tune_initchan (11);
  //pt.tune_initchan (12);
  pinMode(buttonPin, INPUT);
  pinMode(A1, INPUT);
  pinMode(A3, INPUT);
  pinMode(LEDPin1, OUTPUT);
  pinMode(LEDPin2, OUTPUT);
  Serial.begin(9600);
}

void loop () {

  while (play) {
    if (digitalRead(buttonPin) && (buttonTime + debounce) < millis()) {
      play = false;
      switch(song){
        case 0:
          pt.tune_playscore(score); /* start playing */
          song = 1;
          break;
        case 1:
          pt.tune_playscore(score2); /* start playing */
          song = 2;
          break;
        case 2:
          pt.tune_playscore(score3); /* start playing */
          song = 3;
          break;
        case 3:
          pt.tune_playscore(score4); /* start playing */
          song = 4;
          break;
        case 4:
          pt.tune_playscore(score5); /* start playing */
          song = 0;
      }
      buttonTime = millis();
    }
  }

  Serial.println(analogRead(A3));
  analogWrite(LEDPin1, (1.5 * analogRead(A1)));
  analogWrite(LEDPin2, (1.5 * analogRead(A3)));
  //Serial.println(play);
  if (digitalRead(buttonPin) && (buttonTime + debounce) < millis()) {
    play = true;
    pt.tune_stopscore (); /* stop playing */
    analogWrite(LEDPin1, 0);
    analogWrite(LEDPin2, 0);
    buttonTime = millis();
  }
}

Circuit Design

The Beauty and the Beast Themed box:

3 Likes