' ); document.write( '' ); document.write( '' ); document.write( '' ); document.write('');
It's time to kick it up a notch! We'll be hooking up all four of the LEDs and buttons now (red, green, blue, and yellow). You can, of course, pick your own colors for the buttons and the LEDs if you like.
For this, we'll be using Pins 2 - 9 on the Arduino. The pinouts are as follows:
Pin 2 Red LED Output
Pin 3 Green LED Output
Pin 4 Blue LED Output
Pin 5 Yellow LED Output
Pin 6 Red Button Input
Pin 7 Green Button Input
Pin 8 Blue Button Input
Pin 9 Yellow Button Input
If you think you understand how you built the red LED and button, see if you can duplicate this setup 3 times. If you don't feel comfortable yet, don't worry - keep reading for a handy guide!
Your result should look something like this:
In this photo, we used different colored wires, just to make it easier to identify. You can ask around for different colors of wire (we always have plenty extra). You can also use the jumper wires we provided you to save yourself some time when it comes to stripping wires.
And yes! you can peel them apart to separate them.
If you'd like, you're free to follow the pin markings below to get to build your circuit so it's identical to ours.
(everything is shifted 6 from red)
(everything is shifted 6 from green)
(everything is shifted 6 from blue)
It's always good to test your wiring in stages. Once you have a lot of wires, it can be difficult to find what's wrong if there's a lot going on. For this, we've prepared a short demo file which will help you test to see if you've got all the LEDs and buttons wired up correctly.
Take a quick look at the code before uploading it. Without reading further (or watching the video below), take a guess at what might happen. Upload the code to the Arduino!
The expected behavior should be: each time you press a button, that button lights up and stays on, while all other buttons go off.
Wow, it's been really quiet here. Let's add some sound to our toy! For sound, the Arduino will need to rely on an external chip to play audio. The storage on an Arduino is very limited (usually around 32k bytes) and so we need a device that can store and play audio files when the Arduino wants it to. Introducing the DFPlayer!
The pin out diagram for the DFPlayer looks like the below:
While the DFPlayer has many different modes of operation, (some of which are standalone and don't require an Arduino), we'll be using the TX and RX pins on the DFPlayer (transmit and receive, respectively), to communicate with the DFPlayer.
The DFPlayer pulls .mp3 files from a microSD card. The specific naming convention depends on the mode you're using it in. We've preloaded your microSD card with sounds so that it'll work with the Toobers game.
The microSD card only goes in one orientation, and to remove it, simply push the microSD card in once for it to spring back out (known as a push-push mechanism or a catch/latch in mechanical design)
It's time to put everything together! While this schematic may look intimidating, we've already done a good chunk of it. The final piece is to attach the DFplayer and the speaker.
We'll start with placing the DFPlayer. The DFPlayer has two rows of pins, which can straddle the trough nicely to prevent its own pins from shorting (coming into contact) with itself.
Next, we want to connect a mini speaker which will actually be what's playing the sound. The speaker is connected directly to the DFPlayer. Take a look at your speaker, and note down which end it has (on the left are header connectors, and on the right are JST connectors (PH variant))
For prototyping purposes, we can insert a solid-core wire into the ends of both of these (see below) to connect them to the breadboard.
When completed, you should have something that looks like the image below.
And that's it for the wiring! And finally, it's time to upload the final Toobers code, which should play the entire Toobers game.
When you upload this file, your Arduino should immediately come to life and start playing the Toobers start up sound. If it doesn't, double check your wiring. If the sound plays, and all the buttons are working, CONGRATULATIONS! You have your first Toobers prototype! Give yourself a pat on the back. You deserve it.
If something doesn't look right, here are some steps that may help you debug:
Play around with your prototype for a bit. Bask in the glory. See how high of a score you can get. Exciting, isn't it?
If you're reached this step, it's time to try creating your own four button and four LED game! This is an optional activity, as we understand everyone's programming and electronics experience may vary.
Attempt programming your game based on the inputs and outputs you have. Feel free to be creative! Upload your own audio files, and see what you can do with the platform you've created. What about a reaction based game? Could you make something that's two players? Four? The possibilities are endless!
The Arduino ecosystem is designed to be easy to learn, and it provides plenty of resources to teach yourself how to program. Some ideas if you'd like to learn more:
Additionally, when working with the DFPlayer, you should consult this wiki page. Notably, on a Mac, when files are dragged to a SD card, dotfiles are created, so you should use the dot_clean command (as mentioned in the wiki) to clear any ghost files. The specific library we're using can be found on the DFRobot GitHub.
If you need a microSD card reader to upload your own sound files, the lab/staff members have them. You can view how we've currently mapped the sound files for the existing Toobers game.
Have a specific idea you want to implement but don't know how? We're happy to help! Talk to your instructor, mentor, anyone in a lab coat, or reach out to ask-the-tas.
If you've made something you're especially happy with, submit it to us! We'll showcase the top few on the 2.00b site for other students to download, and you might even win a prize ;) This is a completely optional activity.
The zip file should contain:
Please have your game submitted (if you choose to submit one) by Feb 20.
This is also an optional activity, which we'll focus on more in the next lab. Take a few moments and sketch (in your notebook) some concepts for your customized Toobers Toy! While you haven't been given the constraints yet (i.e. size, dimensions) a quick sketch can always inspire something later!
Next lab, we'll be working on soldering the components onto a printed circuit board (PCB) and designing a housing for our Toobers toy in Fusion360. Take your kits with you, but be sure to bring it back for next lab.