Need help with adding code for buzzer/sound to a pong game

I recently built a pong game using a 0.96 color OLED display, using a tutorial that I found on YouTube and the code that was supplied. It works great, but there is no sound. I’d really like to add a buzzer to the code, but after having tried over and over again, I keep failing. I’m really new to coding for Arduino, but I do understand it a tiny bit.

I also found some code from another pong project that I tried to insert into the pong code, but I keep getting many error messages. The biggest problem I am having is where in the original code I should place the buzzer code at. If someone can suggest where I can start, I may be able to figure the rest out.

I am brand new here. My apologies if this request has been placed in the wrong area of the forum. The main code for the pong game is attached to this post.

Thank you.

pong_buzzer.ino (519 Bytes)

pong.ino (9.77 KB)

This is the correct area if you are willing to try to code this yourself and need help.
If you want code written for you, go to “Gigs and Collaborations” and bring your wallet.

W9SPY wrote (in part):

The biggest problem I am having is where in the original code I should place the buzzer code at.

Actually, W9SPY has a big problem because the starting point has issues. For example, BEEPER is not defined, setup() is missing, and loop() is missing.

I admit that I do not know what a “0.96 color OLED display” is.

To post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your complete code.
  2. Paste the complete autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.
  4. If you already posted without code tags, you may add the code tags by
    editing your post. Do not change your existing posts in any other way.
    You may make additional posts as needed.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a clear photograph of the wiring.

Good Luck!

Thanks for your reply. I've tried four times to post the code and your system keeps telling me that I've exceeded the maximum amount of characters. Not sure what to do next...

It is usually considered poor form to change your post after it has been posted. This is covered in item #4. Furthermore, this is NOT my system. The forum belongs to arduino.cc . I do not.

The post limit is around 9000 characters. Thus, pong_buzzer.ino should be fine.
pong.ino might have to be split in half and posted in separate replies. In this case, attaching the file is just fine.

Of course, I don't understand why pong_buzzer.ino has been posted. It appears to just be a portion of pong.ino

I am confused.

If you read my post, I point out that I'm trying to incorporate one code (pong_buzzer) into the pong.ino code. I don't know why you are confused about that.

I'm brand new here, as this is my first post. So forgive me for making mistakes. I'm simply trying to learn how to incorporate new code into some other code that I found and was hoping that someone might address that for me here.

You cannot expect anyone here to have the same libraries that you do, especially when you do not provide a link. Many libraries have identical names but different contents.

I hope that BEEPER is defined inside one of these libraries. I sure cannot see any definition of it.

In C/C++, it is not permitted to define functions inside of other functions. It would appear (in pong.ino) that functions centerPrint, soundPoint, soundBounce, and soundStart are defined within function showScore.

For comparison, notice that functions setup and loop are defined at the top level and are not contained within other functions.

Please: fix this, then provide the fixed code and any error messages. Links to the libraries would be helpful as well.