Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
I am doing a school project that is due very soon, and I am using DfPlayerMini TF-16P, an Arduino Uno and 2 buttons. I was trying to make it so that when I push one button it asks one question, and when I push the other one it asks a different question. I was wondering if anyone could please make me code that would work for this project. I have tried the code below but the code is not working. The buttons don't work, and there is no sound. I have attached my wiring diagram below (sorry if it is bad, this is my first time creating a circuit schematic)
#include "SoftwareSerial.h"
SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
# define ACTIVATED LOW
int buttonNext = 2;
int buttonPause = 3;
boolean isPlaying = false;
void setup () {
digitalWrite(buttonPause, HIGH);
digitalWrite(buttonNext, HIGH);
mySerial.begin (9600);
delay(1000);
playFirst();
isPlaying = true;
}
void loop () {
if (digitalRead(buttonPause) == ACTIVATED)
{
if (isPlaying)
{
pause();
isPlaying = false;
} else
{
isPlaying = true;
play();
}
}
if (digitalRead(buttonNext) == ACTIVATED)
{
if (isPlaying)
{
playNext();
}
}
}
void playFirst()
{
execute_CMD(0x3F, 0, 0);
delay(500);
setVolume(20);
delay(500);
execute_CMD(0x11, 0, 0);
delay(500);
}
void pause()
{
execute_CMD(0x0E, 0, 0);
delay(500);
}
void play()
{
execute_CMD(0x0D, 0, 0);
delay(500);
}
void playNext()
{
execute_CMD(0x01, 0, 1);
delay(500);
}
void setVolume(int volume)
{
execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
delay(2000);
}
void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte
};
//Send the command line to the module
for (byte k = 0; k < 10; k++)
{
mySerial.write( Command_line[k]);
}
}
So when looking at your sketch and schematic - nicely done!
Note: I assume +5V and GND are properly connected to a power supply. You may need more power than your USB port is providing.
Usually with cases like these I'll start looking at some of the basic elements. Here that would be: using buttons, playing sound, and finally combining the two.
When looking at how you're using buttons, I do see two potential issues with how you're using buttons (see also Arduino Buttons).
1. Your code forgets to set the button pins as inputs in "setup ()";
WinSCP WinSCP - Great free tool for (S)FTP/SSH, includes remote editing of text files, copying files, etc.
Animizer Animizer.net provides complete online toolbox for animations (GIF and APNG) - Edit, Assemble, Split or Convert, it's all there.
TinyMediaManager Small, but slick little application to manage your movies and movies meta-data (Windows, MacOS X and Linux!).
Media Player Classic My favorite media player for Windows - light weight and supports all common video formats.
IINA VideoPlayer One of the best media players for MacOS X - it's free and a great alternative for, and more stable than, VLC.
ViMediaManager ViMediaManager is a media manager for Mac OS X, allowing you to gather, store, and manage information, extra art, trailers and television tunes for your movie, television etc for use with for example XBMC.
Links Page These and more of our favorite links can be found on the Links Page.
New Downloads
ConnectMeNow4-v4.0.18-macOS-x86-64.dmgDate: 2024-04-24 - Size: 3.5 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Intel version which works on Intel and Apple Silicon Macs.
ConnectMeNow4-v4.0.18-macOS-arm64.dmgDate: 2024-04-24 - Size: 3 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Apple Silicon version (not suitable for Intel).
MiniWOL2 MacOS (64 bits Apple Silicon)Date: 2023-08-01 - Size: 1.2 MBminiWol is a simple, but effective application to send Wake On LAN to network devices. This is the signed 64 bit MacOS ARM (Apple Silicon) version.
MovieScanner2-2.2.3-Windows-32bit-setup.exeDate: 2023-04-12 - Size: 18.6 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 32 bit Windows version.
MovieScanner2-2.2.2-Linux-GTK-64bits.tar.gzDate: 2023-04-11 - Size: 29.2 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for GTK.
MovieScanner2-2.2.2-Linux-QT5-64bits.tar.gzDate: 2023-04-11 - Size: 29.1 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for QT5.
Downloads Page Find these and more Downloads on the Downloads Page, where you will also find articles references, operating system requirements and categories.
Amazon Ads
Support us by doing your shopping at Amazon.com, either click the link, or click one of the links below …
You can also sponsor us through these Amazon offerings:
Please consider disabling your ad blocker for our website.We rely on these ads to be able to run our website.You can of course support us in other ways (see Support Us on the left).