Components and supplies
Tactile Switch (button/toggle switch)
DFPlayer - A Mini MP3 Player
Resistor 330 ohm
Tactile Switch, Top Actuated
Fisher Price Sit-to-Crawl Sea Turtle
Resistor 1k ohm
Slide Switch (DPDT)
Perfboard
Arduino Nano Every
5 mm LED: Red
Tools and machines
Soldering iron (generic)
Wire (24 gauge)
Super Glue
Tape, Electrical
Tape, Velcro® Stick On Tape/Strip
Screwdriver
Rotary Tool (Dremel)
Project description
Code
Sea Turtle Mod - Code - Main file
arduino
1#include "Led.h" 2#include <DFPlayerMini_Fast.h> 3 4// LED Pins 5const int LED_1_PIN = 3; 6const int LED_1_PATTERN[patternSize] = {400, 400, 400, 400}; 7const int LED_2_PIN = 6; 8const int LED_2_PATTERN[patternSize] = {400, 400, 400, 400}; 9 10// Led object init 11Led led1(LED_1_PIN); 12Led led2(LED_2_PIN); 13 14// Create the Player object 15DFPlayerMini_Fast player; 16 17// Pin for play button 18const int PLAY_BTN = 12; 19 20// DFPlayer Control States 21int fileCount; 22bool toggleState = 1; 23bool lastToggleState = 1; 24bool busyState = 0; 25int lastTrack = 0; // 0 is no track played 26 27void setup() { 28 29 // Init USB serial port for debugging 30 Serial.begin(9600); 31 32 // Init Serial1 for DFPlayer Mini 33 Serial1.begin(9600); 34 player.begin(Serial1, false, 500); 35 36 delay(1000); 37 38 // Set volume 39 player.volume(26); 40 delay(500); 41 42 // Get number of tracks 43 fileCount = player.numSdTracks(); 44 delay(500); 45 46 // Init play button pin 47 pinMode(PLAY_BTN, INPUT_PULLUP); 48 49 // initialize leds, turn them on, and load blink patterns 50 led1.init(); 51 led1.on(); 52 led1.loadPattern(LED_1_PATTERN); 53 54 led2.init(); 55 led2.on(); 56 led2.loadPattern(LED_2_PATTERN); 57 58} 59 60void loop() { 61 62 // get toggle state 63 toggleState = digitalRead(PLAY_BTN); 64 65 // get busy state 66 busyState = player.isPlaying(); 67 68// Debug states 69 Serial.print("Busy: "); 70 Serial.print(busyState); 71 Serial.print(" Last Track: "); 72 Serial.print(lastTrack); 73 Serial.print(" Toggle: "); 74 Serial.print(toggleState); 75 Serial.print(" Last Toggle: "); 76 Serial.print(lastToggleState); 77 Serial.print(" File Count: "); 78 Serial.println(fileCount); 79 80 // if button has been pressed and track is not playing, play the next track 81 if (!toggleState and lastToggleState) { 82 lastToggleState = 0; 83 if (lastTrack == fileCount) { 84 lastTrack = 0; 85 } 86 lastTrack++; 87 player.playFromMP3Folder(lastTrack); 88 delay(500); 89 } else if (toggleState and !lastToggleState) { 90 lastToggleState = 1; 91 } 92 93 // run blink pattern for each led for duration (blinkDur) 94 if (busyState) { 95 led1.blinkPattern(); 96 led2.blinkPattern(); 97 } 98 99} 100
Sea Turtle Mod - Code - Led.h
arduino
1#ifndef MY_LED_H 2#define MY_LED_H 3 4#include <Arduino.h> 5 6const int patternSize = 4; 7 8class Led { 9 private: 10 byte pin; 11 unsigned long lastBlink = 0; 12 int blinkStep = 0; 13 bool state = HIGH; 14 public: 15 int pattern[patternSize]; 16 Led(byte pin); 17 void init(); 18 void off(); 19 void on(); 20 void loadPattern(int arr[patternSize]); 21 void blinkPattern(); 22}; 23 24#endif 25
Sea Turtle Mod - Code - Main file
arduino
1#include "Led.h" 2#include <DFPlayerMini_Fast.h> 3 4// LED Pins 5const int LED_1_PIN = 3; 6const int LED_1_PATTERN[patternSize] = {400, 400, 400, 400}; 7const int LED_2_PIN = 6; 8const int LED_2_PATTERN[patternSize] = {400, 400, 400, 400}; 9 10// Led object init 11Led led1(LED_1_PIN); 12Led led2(LED_2_PIN); 13 14// Create the Player object 15DFPlayerMini_Fast player; 16 17// Pin for play button 18const int PLAY_BTN = 12; 19 20// DFPlayer Control States 21int fileCount; 22bool toggleState = 1; 23bool lastToggleState = 1; 24bool busyState = 0; 25int lastTrack = 0; // 0 is no track played 26 27void setup() { 28 29 // Init USB serial port for debugging 30 Serial.begin(9600); 31 32 // Init Serial1 for DFPlayer Mini 33 Serial1.begin(9600); 34 player.begin(Serial1, false, 500); 35 36 delay(1000); 37 38 // Set volume 39 player.volume(26); 40 delay(500); 41 42 // Get number of tracks 43 fileCount = player.numSdTracks(); 44 delay(500); 45 46 // Init play button pin 47 pinMode(PLAY_BTN, INPUT_PULLUP); 48 49 // initialize leds, turn them on, and load blink patterns 50 led1.init(); 51 led1.on(); 52 led1.loadPattern(LED_1_PATTERN); 53 54 led2.init(); 55 led2.on(); 56 led2.loadPattern(LED_2_PATTERN); 57 58} 59 60void loop() { 61 62 // get toggle state 63 toggleState = digitalRead(PLAY_BTN); 64 65 // get busy state 66 busyState = player.isPlaying(); 67 68// Debug states 69 Serial.print("Busy: "); 70 Serial.print(busyState); 71 Serial.print(" Last Track: "); 72 Serial.print(lastTrack); 73 Serial.print(" Toggle: "); 74 Serial.print(toggleState); 75 Serial.print(" Last Toggle: "); 76 Serial.print(lastToggleState); 77 Serial.print(" File Count: "); 78 Serial.println(fileCount); 79 80 // if button has been pressed and track is not playing, play the next track 81 if (!toggleState and lastToggleState) { 82 lastToggleState = 0; 83 if (lastTrack == fileCount) { 84 lastTrack = 0; 85 } 86 lastTrack++; 87 player.playFromMP3Folder(lastTrack); 88 delay(500); 89 } else if (toggleState and !lastToggleState) { 90 lastToggleState = 1; 91 } 92 93 // run blink pattern for each led for duration (blinkDur) 94 if (busyState) { 95 led1.blinkPattern(); 96 led2.blinkPattern(); 97 } 98 99} 100
Sea Turtle Mod - Code - Led.cpp
arduino
1#include "Led.h" 2 3Led::Led(byte pin) { 4 this->pin = pin; 5} 6 7void Led::init() { 8 pinMode(pin, OUTPUT); 9 off(); 10} 11 12void Led::off() { 13 digitalWrite(pin, LOW); 14} 15void Led::on() { 16 digitalWrite(pin, HIGH); 17} 18 19void Led::loadPattern(int arr[patternSize]) { 20 for (int i = 0; i < patternSize; i++) { 21 pattern[i] = arr[i]; 22 } 23} 24 25void Led::blinkPattern() { 26 unsigned long currentMillis = millis(); 27 if (currentMillis - lastBlink >= pattern[blinkStep]) { 28 29 // debugging output 30// Serial.print("Last Blink: "); 31// Serial.print(lastBlink); 32// Serial.print(" Blink Step: "); 33// Serial.print(blinkStep); 34// Serial.print(" Blink Interval: "); 35// Serial.println(pattern[blinkStep]); 36 37 if (state == LOW) { 38 state = HIGH; 39 on(); 40 } else { 41 state = LOW; 42 off(); 43 } 44 lastBlink = currentMillis; 45 if (blinkStep == patternSize-1) { 46 blinkStep = 0; 47 } else { 48 blinkStep++; 49 } 50 } 51} 52
Sea Turtle Mod - Code - Led.h
arduino
1#ifndef MY_LED_H 2#define MY_LED_H 3 4#include <Arduino.h> 5 6const int patternSize = 4; 7 8class Led { 9 private: 10 byte pin; 11 unsigned long lastBlink = 0; 12 int blinkStep = 0; 13 bool state = HIGH; 14 public: 15 int pattern[patternSize]; 16 Led(byte pin); 17 void init(); 18 void off(); 19 void on(); 20 void loadPattern(int arr[patternSize]); 21 void blinkPattern(); 22}; 23 24#endif 25
Downloadable files
Sea Turtle Audio Mod - Schematic
Sea Turtle Audio Mod - Schematic
Sea Turtle Audio Mod - Schematic
Sea Turtle Audio Mod - Schematic
Comments
Only logged in users can leave comments
pbiscuits
0 Followers
•0 Projects
Table of contents
Intro
1
0