QC

Mp3 player with vinyl record frame and screen

A simple Mp3 player with LCD screen for use in vinyl record frames.

Devices and components

Arduino-Nano

16x2 LCD screen with I²C interface

Closed stereo speaker - 3 W 8 Ω

DFPlayer - A mini MP3 player

TTP223 touch sensor module

Materials and tools

Soldering kit

Software and tools

Arduino IDE

Project description

Mp3 player for vinyl frames

A simple Mp3 player to use in Vinyl Record Frame

1#include "SoftwareSerial.h"
2#include <LiquidCrystal_I2C.h>
3
4SoftwareSerial playerSerial(10, 11); //Define dfplayer module.
5LiquidCrystal_I2C lcd (0x26, 16, 2); //Define 16x2 LCD.
6
7# define Start_Byte 0x7E
8# define Version_Byte 0xFF
9# define Command_Length 0x06
10# define End_Byte 0xEF
11# define Acknowledge 0x00
12# define ACTIVATED LOW
13
14//ints to keep track of the touch counts and current track.
15int touchCount = 0;
16int currTrack = 0;
17
18//Initial lcd text (Album title).
19String lcdText = "Enter the Wu-tang";
20//Track array
21String trackName[11] = {"Bring Da Ruckus", "Shame On a ", "Clan In Da Front", "Wu-Tang: 7th Chamber", "Can It Be All So Simple", "Da Mystery of Chessboxin'", "Wu-Tang Clain Ain't Nuthin ta F' Wit", "C.R.E.A.M", "Method Man", "Protect Ya Neck", "Tearz"};
22
23void setup()
24{
25 //Start serial and player serial.
26 Serial.begin(9600);
27 playerSerial.begin(9600);
28
29 //Set pinmode.
30 pinMode(8, INPUT);
31
32 //Initilise LCD.
33 lcd.init();
34 lcd.clear();
35 lcd.backlight();
36
37 //Configure dfplayer.
38 //Repeat Play.
39 execute_CMD(0x11, 0, 0);
40 delay(500);
41 //Set volume (to max).
42 execute_CMD(0x06, 0, 30);
43 delay(500);
44}
45
46void doAudio(){
47 if(touchCount > 5){
48 //Reset module.
49 execute_CMD(0x0C, 0, 0);
50 touchCount = 0;
51 currTrack = 0;
52 lcdText = "Enter the Wu-tang";
53 }
54
55 else{
56 switch (touchCount){
57 case 1:
58 //Play (first track).
59 execute_CMD(0x0D,0,1);
60 delay(1000);
61 //Reset touch counter.
62 touchCount = 0;
63 //Clear lcd and set text based on current track.
64 lcd.clear();
65 lcdText = trackName[currTrack];
66 break;
67
68 case 2:
69 //Send next track.
70 execute_CMD(0x01, 0, 0);
71 delay(1000);
72 touchCount = 0;
73 currTrack++;
74 lcd.clear();
75 lcdText = trackName[currTrack];
76 break;
77
78 case 3:
79 //Send previous track.
80 execute_CMD(0x02, 0, 0);
81 delay(1000);
82 touchCount = 0;
83 currTrack--;
84 lcd.clear();
85 lcdText = trackName[currTrack];
86 break;
87 }
88 }
89
90}
91
92void loop()
93{
94
95 //Set and print lcd text.
96 lcd.setCursor(0, 1);
97 //Print lcdText (Current track pulled from array).
98 lcd.print(lcdText);
99 //Scroll text left.
100 lcd.command(0x18);
101 //Delay which is needed to stop fast scrolling & fast button incrementing.
102 delay(150);
103
104 //Current track is out of range of our array, reset.
105 if(currTrack > 11){
106 currTrack = 0;
107 }
108
109 //Check for touch/button press.
110 if(digitalRead(8) == HIGH) {
111 touchCount++;
112 }
113 else{
114 //No touch, do audio commands.
115 doAudio();
116 }
117
118 //Debug stuff.
119 Serial.println(touchCount);
120}
121
122
123//Not my code, credit goes to Nick Koumaris @ https://www.electronics-lab.com/project/mp3-player-using-arduino-dfplayer-mini/
124void execute_CMD(byte CMD, byte Par1, byte Par2)
125// Excecute the command and parameters
126{
127// Calculate the checksum (2 bytes)
128word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
129// Build the command line
130byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
131Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
132//Send the command line to the module
133for (byte k=0; k<10; k++)
134{
135playerSerial.write( Command_line[k]);
136}
137
138}




Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.

SendData

Điều khiển trạng thái qua Firebase Trạng thái hiện tại: Đang tải... ĐỔI TRẠNG THÁI