r/ArduinoHelp • • 2h ago

Arduino DFPlayer Zelda OOT/MM coding project help

1 Upvotes

Hello I am currently working on a dfplayer project, that plays the ocarina songs from zelda OOT & MM. I started this project months ago and I thought it was time for an upgrade, so I was gonna move off the connection to my PC and to a PCB. However, before that I wanted to fix one major issue...the code. Months ago I did not think much of the code bc I had it generated through chatgpt but then for this is upgrade of the project, I thought I should make most of the code myself instead of relying on LLM to do it for me. well I attempted it with ideas I had to improve and clean the code, however that caused me to hit a wall. I would like some hard critiquing guidance on my mistakes and what I can learn so I can do better. (I'm still rusty and practicing with arduino so some of what I wrote might be very wrong)

Here the changes I made so there is a better picture of what I am talking about:

//new#
void checkInput(int buttonPressed) {//function of checking of which button was pressed 


  // 🔊 Play note
  dfplayer.play(buttonPressed + 1);//tells the dfplayer to play corresponding sound to the button
  delay(250);//pauses for 250 miliseconds, to give time for the next note to play


  // Store input
  inputSequence[inputIndex] = buttonPressed;//remembers the button sequence by storing the pressed button's index in the current array position
  inputIndex++;//increases the index by one, so the program knows how many notes were entered


  
   bool match++;//I replace the repeating Booleans with a single line that add the matches but not sure if this would work 
  }


  for (int i = 0; i < inputIndex; i++) {//a for loop to examine every note/button entered by the user


    if (i >= song_len || inputSequence[i] != song[i]++) match = false;//I decide to use a single line that loops with the function
}


  // ===== FULL MATCHES =====


  if (match1 && inputIndex == song1_len) { 
dfplayer.play(27); 
delay(1500); 
dfplayer.play(song_track++); resetInput(); return; }//checks if  both sequence and sequence length match the song, if its correct it tells the dfplayer to play the correct sound followed by a 1.5 sec delay, tells the dfplayer to play the song, calls the resetInput() function, return exits the checkInput function
  
  // ❌ WRONG INPUT
  if (!match++) {


    // dfplayer.play(28); // optional error
    resetInput();//calls the resetInput() function and clears current sequence 
    return;//exits the current function
  }

//old#2
void checkInput(int buttonPressed) {//function of checking of which button was pressed 


  // 🔊 Play note
  dfplayer.play(buttonPressed + 1);//tells the dfplayer to play corresponing sound to the button
  delay(250);//pauses for 250 miliseconds, to give time for the next note to play


  // Store input
  inputSequence[inputIndex] = buttonPressed;//remembers the button sequence by storing the pressed button's index in the current array position
  inputIndex++;//increases the index by one, so the program knows how many notes were entered


  // ===== MATCH FLAGS =====
  //th boolean variables are used to deterime if the current sequence matches a song
  bool match1 = true;
  bool match2 = true;
  bool match3 = true;
  bool match4 = true;
  bool match5 = true;
  bool match6 = true;
  bool match7 = true;
  bool match8 = true;
  bool match9 = true;
  bool match10 = true;
  bool match11 = true;
  bool match12 = true;
  bool match13 = true;
  bool match14 = true;
  bool match15 = true;
  bool match16 = true;
  bool match17 = true;
  bool match18 = true;
  bool match19 = true;
  bool match20 = true;
  bool match21 = true;


  for (int i = 0; i < inputIndex; i++) {//a for loop to examine every note/button entered by the user


    if (i >= song1_len || inputSequence[i] != song1[i]) match1 = false;// i >= song1_len checks if the input goes beyond the length of the song, inputSequence[i] != song1[i] checks if the user's differs from the note expectd by the song
    if (i >= song2_len || inputSequence[i] != song2[i]) match2 = false;
    if (i >= song3_len || inputSequence[i] != song3[i]) match3 = false;
    if (i >= song4_len || inputSequence[i] != song4[i]) match4 = false;
    if (i >= song5_len || inputSequence[i] != song5[i]) match5 = false;
    if (i >= song6_len || inputSequence[i] != song6[i]) match6 = false;
    if (i >= song7_len || inputSequence[i] != song7[i]) match7 = false;
    if (i >= song8_len || inputSequence[i] != song8[i]) match8 = false;
    if (i >= song9_len || inputSequence[i] != song9[i]) match9 = false;
    if (i >= song10_len || inputSequence[i] != song10[i]) match10 = false;
    if (i >= song11_len || inputSequence[i] != song11[i]) match11 = false;
    if (i >= song12_len || inputSequence[i] != song12[i]) match12 = false;
    if (i >= song13_len || inputSequence[i] != song13[i]) match13 = false;
    if (i >= song14_len || inputSequence[i] != song14[i]) match14 = false;
    if (i >= song15_len || inputSequence[i] != song15[i]) match15 = false;
    if (i >= song16_len || inputSequence[i] != song16[i]) match16 = false;
    if (i >= song17_len || inputSequence[i] != song17[i]) match17 = false;
    if (i >= song18_len || inputSequence[i] != song18[i]) match18 = false;
    if (i >= song19_len || inputSequence[i] != song19[i]) match19 = false;
    if (i >= song20_len || inputSequence[i] != song20[i]) match20 = false;
    if (i >= song21_len || inputSequence[i] != song21[i]) match21 = false;
}


  // ===== FULL MATCHES =====


  if (match1 && inputIndex == song1_len) { dfplayer.play(27); delay(1500); dfplayer.play(song1_track); resetInput(); return; }//checks if  both sequence and sequence length match the song, if its correct it tells the dfplayer to play the correct sound followed by a 1.5 sec delay, tells the dfplayer to play the song, calls the resetInput() function, return exits the checkInput function
  if (match2 && inputIndex == song2_len) { dfplayer.play(27); delay(1500); dfplayer.play(song2_track); resetInput(); return; }
  if (match3 && inputIndex == song3_len) { dfplayer.play(27); delay(1500); dfplayer.play(song3_track); resetInput(); return; }
  if (match4 && inputIndex == song4_len) { dfplayer.play(27); delay(1500); dfplayer.play(song4_track); resetInput(); return; }
  if (match5 && inputIndex == song5_len) { dfplayer.play(27); delay(1500); dfplayer.play(song5_track); resetInput(); return; }
  if (match6 && inputIndex == song6_len) { dfplayer.play(27); delay(1500); dfplayer.play(song6_track); resetInput(); return; }
  if (match7 && inputIndex == song7_len) { dfplayer.play(27); delay(1500); dfplayer.play(song7_track); resetInput(); return; }
  if (match8 && inputIndex == song8_len) { dfplayer.play(27); delay(1500); dfplayer.play(song8_track); resetInput(); return; }
  if (match9 && inputIndex == song9_len) { dfplayer.play(27); delay(1500); dfplayer.play(song9_track); resetInput(); return; }
  if (match10 && inputIndex == song10_len) { dfplayer.play(27); delay(1500); dfplayer.play(song10_track); resetInput(); return; }
  if (match11 && inputIndex == song11_len) { dfplayer.play(27); delay(1500); dfplayer.play(song11_track); resetInput(); return; }
  if (match12 && inputIndex == song12_len) { dfplayer.play(27); delay(1500); dfplayer.play(song12_track); resetInput(); return; }
  if (match13 && inputIndex == song13_len) { dfplayer.play(27); delay(1500); dfplayer.play(song13_track); resetInput(); return; }
  if (match14 && inputIndex == song14_len) { dfplayer.play(27); delay(1500); dfplayer.play(song14_track); resetInput(); return; }
  if (match15 && inputIndex == song15_len) { dfplayer.play(27); delay(1500); dfplayer.play(song15_track); resetInput(); return; }
  if (match16 && inputIndex == song16_len) { dfplayer.play(27); delay(1500); dfplayer.play(song16_track); resetInput(); return; }
  if (match17 && inputIndex == song17_len) { dfplayer.play(27); delay(1500); dfplayer.play(song17_track); resetInput(); return; }
  if (match18 && inputIndex == song18_len) { dfplayer.play(27); delay(1500); dfplayer.play(song18_track); resetInput(); return; }
  if (match19 && inputIndex == song19_len) { dfplayer.play(27); delay(1500); dfplayer.play(song19_track); resetInput(); return; }
  if (match20 && inputIndex == song20_len) { dfplayer.play(27); delay(1500); dfplayer.play(song20_track); resetInput(); return; }
  if (match21 && inputIndex == song21_len) { dfplayer.play(27); delay(1500); dfplayer.play(song21_track); resetInput(); return; }


  // ❌ WRONG INPUT
  if (!match1 && !match2 && !match3 && !match4 && !match5 &&
      !match6 && !match7 && !match8 && !match9 && !match10 &&
      !match11 && !match12 && !match13 && !match14 && !match15 &&
      !match16 && !match17 && !match18 && !match19 && !match20 &&
      !match21) {//checks if the sequence is correct


    // dfplayer.play(28); // optional error
    resetInput();//calls the resetInput() function and clears current sequence 
    return;//exits the current function
  }

//new#1 
for(int i = 0; i < inputSequence[MAX_LEN]; i++){//idk if this part will work, but its supposed to the arrays, the length of each array, and the which number file to play, I was trying to see if a for loop would do it but now i am not sure
  int song[] = {};
  int song_len++;
  int song_track++;
}

//old#1
// Zelda's Lullaby: B D2 A B D2 A
int song1[] = {1, 3, 0, 1, 3, 0};
int song1_len = 6;
int song1_track = 6;


// Epona's Song: D2 B A D2 B A
int song2[] = {3, 1, 0, 3, 1, 0};
int song2_len = 6;
int song2_track = 7;


// Saria's Song: F A B F A B
int song3[] = {4, 0, 1, 4, 0, 1};
int song3_len = 6;
int song3_track = 8;


// Sun's Song: A F D2 A F D2
int song4[] = {0, 4, 3, 0, 4, 3};
int song4_len = 6;
int song4_track = 9;


// Song of Time: A D F A D F
int song5[] = {0, 2, 4, 0, 2, 4};
int song5_len = 6;
int song5_track = 10;


// Song of Storms: D F D2 D F D2
int song6[] = {2, 4, 3, 2, 4, 3};
int song6_len = 6;
int song6_track = 11;

etc. 

r/ArduinoHelp • • 13h ago

Help in my DLD project-> Smart parking system

Post image
1 Upvotes

No use of microcontroller is allowed

What features i can add in this project, and which ICs will be appropriate to use.

Thanks in advance ❤️


r/ArduinoHelp • • 13h ago

[advice] Issue with feather based Terrarium/Paludarium climate control

Thumbnail reddit.com
1 Upvotes

r/ArduinoHelp • • 19h ago

Dim brightness on TFT Display (ST7735/ST7735S)

Post image
1 Upvotes

r/ArduinoHelp • • 1d ago

Help me out

Thumbnail gallery
3 Upvotes

r/ArduinoHelp • • 1d ago

NEED HELP ‼️🙇‍♂️🙇‍♂️🥹

1 Upvotes

Hello! I am a Grade 12 STEM-Allied Health student. I am reaching out for some guidance/help on behalf of our research group leader regarding our scaled down prototype: an Low-Cost Arduino-based Patient Bed-Exit Monitoring and Alert System! 🙇‍♂️ For our research project ^

We are specifically looking for advice; please note that we do not have a budget to pay anyone for their assistance. Thank you! 🙇‍♂️

Hypothetically, if our setup consists of:

- Arduino Uno

- HX711 sensors

- 4 load cells (bar-type) in a Wheatstone bridge configuration—placed under the bed to detect when a patient exits—

a buzzer, an LED, and an ESP32 Wi-Fi/Bluetooth module

What kind of power source should we use, or what would be the most suitable power source for a prototype with this configuration?

Also, do you have any tips regarding the wiring and coding for beginners? Since we are in the Allied Health strand, we don’t really have any prior knowledge about this! 🥹🥹🙇‍♂️🙇‍♂️

(Our entire Grade 12 batch was assigned an Arduino-based developmental research project, which is why we’re in this situation! 💔)


r/ArduinoHelp • • 1d ago

Arduino-Honigglasabfüller mit 6-Positionen-Drehteller + Wägezelle – hat jemand schon mal so etwas gebaut?

Post image
1 Upvotes

r/ArduinoHelp • • 2d ago

Building a mini wokwi sort of thing

Thumbnail reddit.com
1 Upvotes

r/ArduinoHelp • • 2d ago

Trouble playing mp3 files on aDFPlayer - Mini MP3 Player

2 Upvotes

Below is a small part of an Arduino sketch to play 3 files through a DFPlayer. The files play so everything is hooked up correctly. The problem is the files play 2 then 3 then 1. Out of order. Any idea why?

  
  myDFPlayer.volume(5);  //Set volume value. From 0 to 30 
{

myDFPlayer.play(1);  //Play the first mp3

  delay(10000);

  myDFPlayer.play(2);  //Play the second mp3

  delay(10000);

  myDFPlayer.play(3);  //Play the third mp3

}

void loop()


r/ArduinoHelp • • 4d ago

LED Strip connection

Thumbnail reddit.com
1 Upvotes

r/ArduinoHelp • • 4d ago

Issue with my Arduino UNO

Thumbnail reddit.com
1 Upvotes

r/ArduinoHelp • • 4d ago

2 sensors on the same bus

1 Upvotes

I am working of an iot project for my diploma I have a max30102 and an mpu6050 Al says I can connect them on the same I2C bus and the code will be simpler but I am a beginner at coding and this project is already haunting my nights enough so any advice from professionals will coding actually be simpler and any tips on how the code will look like and frankly I don't trust AI nor do i want to fully rely on it for code

My max is connected the SDA and SCL of the esp but my mpu is connect to 2 and 15

Any advice on this will be very helpful


r/ArduinoHelp • • 5d ago

I Want to Learn Arduino from Scratch – Need Guidance!

6 Upvotes

Title:

Hi everyone!

I'm a beginner in Arduino and I want to learn it from the basics. I have an Arduino Uno board, but I'm not sure how to start.

I especially want to learn:

- Arduino programming.

- How to connect LEDs, push buttons, resistors, sensors, etc.

- How to understand circuit diagrams and wiring connections.

- How to connect components to the correct Arduino pins.

- How to build simple projects step by step.

I'm looking for beginner-friendly tutorials, YouTube channels, websites, or learning resources.

I would really appreciate it if experienced Arduino users could guide me on how to start learning from zero.

Thank you! Any advice would be helpful.


r/ArduinoHelp • • 6d ago

Hey I'm new CE student need help

Thumbnail gallery
3 Upvotes

Hey I'm creating a automatic solor tracking project with 2 servo and 4 phtoresisters and I printed them using a 3D printer and now everything is going good servo but when i plug the arduino to my laptop it work for a few second then stoped so it's might be the consistent power needed? I don't know I need help if you want the design or code feel free to ask


r/ArduinoHelp • • 6d ago

need help with connecting sd card reader to esp32

Thumbnail gallery
1 Upvotes

r/ArduinoHelp • • 7d ago

Arduino circuit connection

Post image
1 Upvotes

Anyone well versed in arduino . Please help me to built a little circuit for when i touch the push button ,the led turns on for 2 sec then off


r/ArduinoHelp • • 7d ago

Arduino ide error

Post image
1 Upvotes

I'm trying to upload my project to my ESP32-C3 SuperMini, but I keep getting this error. My Windows account was originally created with the name "Dari M", but Arduino no longer recognizes it correctly and only detects "Dari", without the "M". How can I fix this problem without changing my Windows account?

Can someoane help me pls?


r/ArduinoHelp • • 7d ago

how to learn arduino from simulator app

1 Upvotes

r/ArduinoHelp • • 8d ago

Fought a Siemens S7-1200 for years, replaced it with a CANADUINO PLC ESP32-C6 programmed by ChatGPT (TARS). Now fighting analog sensors and ADCs!

Thumbnail
reddit.com
1 Upvotes

r/ArduinoHelp • • 8d ago

Project help

Post image
1 Upvotes

r/ArduinoHelp • • 9d ago

Attendance checker with Arduino :P

1 Upvotes

Currently trying to survive our robotics project that utilizes Arduino, I just wanted to ask for some guidance before we go through with what we are planning to do.

As of right now the general plan we have is to create an automated attendance tracker that utilizes the RFID Scanner and fingerprint biometrics for attendance (Which is already built into our IDs). Along with this we want to incorporate an SMS system where a text will be sent to the parent/provided number of each student when they arrive and clock out. (Hopefully, if possible, the message can specify if they are late, or cutting; they didn't log out) I would like to ask what components would we need since we are provided an Arduino kit, but I already expect that we need to spend more to make our prototype possible. The goal is by the end of day or week, the data collected can be extraced or uploaded into a spreadsheet where everything is organized.

Other ideas we try to implement is maybe implementing a temperature sensor so that the students going to school can also be taken in for health reasons and saved to the spreadsheet. Of course however we acknowledge that not everything we want can be integrated, but we just want to lay down some of the ideas we have.

Before getting deeper into the prototype, I would just like to ask if this is feasible, worth it, and what components and factors we would need to think about when developing it. Other parts we thought about including are a PIR sensor to detect whether or not someone is nearby so the LCD screen can power on to save electricity, etc.

Any guidance and recommendations are appreciated, thank you so much!