pbiscuits
Published © GPL3+

Sea Turtle Toy Audio Mod

Modded my daughter's Fisher Price Sea Turtle toy to play custom audio files.

IntermediateShowcase (no instructions)1,165
Sea Turtle Toy Audio Mod

Things used in this project

Hardware components

Arduino Nano Every
Arduino Nano Every
×1
DFPlayer - A Mini MP3 Player
DFRobot DFPlayer - A Mini MP3 Player
×1
Fisher Price Sit-to-Crawl Sea Turtle
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×1
5 mm LED: Red
5 mm LED: Red
×2
Resistor 330 ohm
Resistor 330 ohm
×2
Resistor 1k ohm
Resistor 1k ohm
×1
Slide Switch (DPDT)
×1
Tactile Switch (button/toggle switch)
×1

Hand tools and fabrication machines

Rotary Tool (Dremel)
Soldering iron (generic)
Soldering iron (generic)
Wire (24 gauge)
Perfboard
Tape, Electrical
Tape, Electrical
Tape, Velcro® Stick On Tape/Strip
Tape, Velcro® Stick On Tape/Strip
Super Glue
Screwdriver

Story

Read more

Schematics

Sea Turtle Audio Mod - Schematic

Code

Sea Turtle Mod - Code - Main file

Arduino
#include "Led.h"
#include <DFPlayerMini_Fast.h>

// LED Pins
const int LED_1_PIN = 3;
const int LED_1_PATTERN[patternSize] = {400, 400, 400, 400};
const int LED_2_PIN = 6;
const int LED_2_PATTERN[patternSize] = {400, 400, 400, 400};

// Led object init
Led led1(LED_1_PIN);
Led led2(LED_2_PIN);

// Create the Player object
DFPlayerMini_Fast player;

// Pin for play button
const int PLAY_BTN = 12;

// DFPlayer Control States
int fileCount;
bool toggleState = 1;
bool lastToggleState = 1;
bool busyState = 0;
int lastTrack = 0; // 0 is no track played

void setup() {
  
  // Init USB serial port for debugging
  Serial.begin(9600);
  
  // Init Serial1 for DFPlayer Mini
  Serial1.begin(9600);
  player.begin(Serial1, false, 500);

  delay(1000);
  
  // Set volume
  player.volume(26);
  delay(500);

  // Get number of tracks
  fileCount = player.numSdTracks();
  delay(500);

  // Init play button pin
  pinMode(PLAY_BTN, INPUT_PULLUP);
  
  // initialize leds, turn them on, and load blink patterns
  led1.init();
  led1.on();
  led1.loadPattern(LED_1_PATTERN);
  
  led2.init();
  led2.on();
  led2.loadPattern(LED_2_PATTERN);
  
}

void loop() {

  // get toggle state
  toggleState = digitalRead(PLAY_BTN);

  // get busy state
  busyState = player.isPlaying();

// Debug states
  Serial.print("Busy: ");
  Serial.print(busyState);
  Serial.print(" Last Track: ");
  Serial.print(lastTrack);
  Serial.print(" Toggle: ");
  Serial.print(toggleState);
  Serial.print(" Last Toggle: ");
  Serial.print(lastToggleState);
  Serial.print(" File Count: ");
  Serial.println(fileCount);

  // if button has been pressed and track is not playing, play the next track
  if (!toggleState and lastToggleState) {
    lastToggleState = 0;
    if (lastTrack == fileCount) {
      lastTrack = 0;
    }
    lastTrack++;
    player.playFromMP3Folder(lastTrack);
    delay(500);
  } else if (toggleState and !lastToggleState) {
    lastToggleState = 1;
  }
  
  // run blink pattern for each led for duration (blinkDur)
  if (busyState) {
    led1.blinkPattern();
    led2.blinkPattern();
  }

}

Sea Turtle Mod - Code - Led.cpp

Arduino
#include "Led.h"

Led::Led(byte pin) {
  this->pin = pin;
}

void Led::init() {
  pinMode(pin, OUTPUT);
  off();
}

void Led::off() {
  digitalWrite(pin, LOW);
}
void Led::on() {
  digitalWrite(pin, HIGH);
}

void Led::loadPattern(int arr[patternSize]) {
  for (int i = 0; i < patternSize; i++) {
    pattern[i] = arr[i];
  }
}

void Led::blinkPattern() {
  unsigned long currentMillis = millis();
  if (currentMillis - lastBlink >= pattern[blinkStep]) {

    // debugging output
//    Serial.print("Last Blink: ");
//    Serial.print(lastBlink);
//    Serial.print(" Blink Step: ");
//    Serial.print(blinkStep);
//    Serial.print(" Blink Interval: ");
//    Serial.println(pattern[blinkStep]);

    if (state == LOW) {
      state = HIGH;
      on();
    } else {
      state = LOW;
      off();
    }
    lastBlink = currentMillis;
    if (blinkStep == patternSize-1) {
      blinkStep = 0; 
    } else {
      blinkStep++;
    }
  }
}

Sea Turtle Mod - Code - Led.h

Arduino
#ifndef MY_LED_H
#define MY_LED_H

#include <Arduino.h>

const int patternSize = 4;

class Led {
  private:
    byte pin;
    unsigned long lastBlink = 0;
    int blinkStep = 0;
    bool state = HIGH;
  public:
    int pattern[patternSize];
    Led(byte pin);
    void init();
    void off();
    void on();
    void loadPattern(int arr[patternSize]);
    void blinkPattern();
};

#endif

Credits

pbiscuits

pbiscuits

1 project • 0 followers

Comments