Combine two Arduino projects into one PCB with the Arduino codes combined.

I have a keypad.h project and a MP3 player project and I want to combine the two into one. I am using the matrix 3 by 4 and a MTV020M01 MP3 player. I have both codes and projects together. I need to combine into one project and then onto a pcb where I can program the components with the Arduino code but without the Arduino circuit board itself. So technically I need a bootloader. But I need to combine both projects. Thanks!

Is there a question in there somewhere?

Although you can combine two different programs (sketches) you can't simply cut-and-paste.

If you're writing the program yourself it should be no problem but if you are copying someone else's programs you'll have to full-understand how they work and you'll essentially have to re-write/re-create the functionality of at least one of the programs yourself.

Then how do I combine the breadboard projects together

First I need to combine the two projects before I combine the code. How do I combine the project? Not code.

You make sure that the components of the project occupy different pins. Or in the case of I2C devices have different addresses. Or in the case of SPI devices have separate chip enable lines.

If you want more than generic advice be more specific about what these projects are and post the schematic of both.

I have the code for my keypad

include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 3;

char hexaKeys[ROWS][COLS] = {

{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}

};
byte rowPins[ROWS] = {5, 6, 7, 8};
byte colPins[COLS] = {2, 3, 4};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
Serial.begin(9600);
}

void loop(){
char customKey = customKeypad.getKey();

if (customKey){
Serial.println(customKey);
}
}

I want to combine the keypad code with the sample code from the Arduino starter kit book project number 7.

/*
Keyboard

Plays a pitch that changes based on a changing
input circuit:

  • 3 pushbuttons from +5V to analog in 0 through
    3
  • 3 10K resistors from analog in 0 through 3 to
    ground
  • 8-ohm speaker on digital pin 8
    */

int pos = 0;

void setup()
{
pinMode(A0, INPUT);
pinMode(8, OUTPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
}

void loop()
{
// if button press on A0 is detected
if (digitalRead(A0) == HIGH) {
tone(8, 440, 100); // play tone 57 (A4 = 440 Hz)
}
// if button press on A1 is detected
if (digitalRead(A1) == HIGH) {
tone(8, 494, 100); // play tone 59 (B4 = 494 Hz)
}
// if button press on A0 is detected
if (digitalRead(A2) == HIGH) {
tone(8, 523, 100); // play tone 60 (C5 = 523 Hz)
}
delay(10); // Delay a little bit to improve simulation performance
}

I want to combine the two codes so that the keypad plays a tone;
when a button is pressed on the keypad ( for example, button 1 ), play tone __ = ___ Hz

How would I do this? If you need a better explanation, contact me on facebook = Facebook

Take the first code and replace the loop function of it with the loop function of the second.
Then add the

char customKey = customKeypad.getKey();

And change each

 if (digitalRead(A1) == HIGH) {
    tone(8, 494, 100); // play tone 59 (B4 = 494 Hz)

with a string of

 if (customKey == '*') {
    tone(8, 494, 100); // play tone 59 (B4 = 494 Hz)

Where '*' is the character you want to associate with that note.

I understand what you are telling me to do, but what would the code you are telling me to add like like in my code as a whole?
I want to add the second code into the first code

how do I make the first code have the parts of the second code to make the first code say, when ( what ever button they pressed), play tone_=_Hz

jaredm2195:
how do I make the first code have the parts of the second code to make the first code say, when ( what ever button they pressed), play tone_=_Hz

Use the editor in the IDE

I know that, but I am asking what the code would look like as a whole if I combined them and put the second code into the first one and just added the part with the tone playing.

jaredm2195:
I know that, but I am asking what the code would look like as a whole if I combined them and put the second code into the first one and just added the part with the tone playing.

It would look like the code you have now only longer and some lines would be different. That is what it would look like.

Are you saying you want me to write the whole thing for you?
If so:-

  1. We don't do that here, see BEGINNERS: We rarely write code for you, but will help you write it for yourself - General Discussion - Arduino Forum

  2. You already said:-

I understand what you are telling me to do,

So what exactly is the problem?

what I am saying is that I am using the first code as the base code and adding the tone part from the second code into the first code!!!!!!!!!!

Grumpy_Mike:

 if (digitalRead(A1) == HIGH) {

tone(8, 494, 100); // play tone 59 (B4 = 494 Hz)



with a string of


if (customKey == '*') {
    tone(8, 494, 100); // play tone 59 (B4 = 494 Hz)



Where '*' is the character you want to associate with that note.

what I am saying is that I am using the first code as the base code and adding the tone part from the second code into the first code

Yes if you like.

what do you mean when you say yes if you like

would this code make sense for the task I need to complete.
when ( what ever button they pressed on the matrix keypad 3 by 4), play tone_=_Hz

here is the code:

include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 3;

char hexaKeys[ROWS][COLS] = {

{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}

};
byte rowPins[ROWS] = {5, 6, 7, 8};
byte colPins[COLS] = {2, 3, 4};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

int notes[] = {440,294,330,349};

void setup(){
Serial.begin(9600);
}

void loop(){
char customKey = customKeypad.getKey();
if (customKey == '1') {
** tone(9, notes[0]); // play tone (A4 = 440 Hz)**
** }**
** else{**
** noTone(9);**
** }**
if (customKey){
Serial.println(customKey);
}
}

That is the sort of thing.
However the

else{
   noTone(9);

Bit means it will never produce any sound because all keys are not pressed at the same time and any unpressed key will stop the sound. Just leave that part out or use it for when no key is pressed.

How would I use it for when no key is pressed? Would I just leave it the way it is or do something else? also, what would I do to play the sound? would I just put a piezo speaker in anywhere and it will just play?

?

How do I use it for when no key is pressed? Would I just leave it the way it is or do something else? also, how can I hook up the dfplayer to work with this project. Also, I would need the schematic