Go Down

Topic: Combine two Arduino projects into one PCB with the Arduino codes combined. (Read 1 time) previous topic - next topic

jaredm2195

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!

DVDdoug

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.

jaredm2195


jaredm2195

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

Grumpy_Mike

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.

jaredm2195

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 = https://www.facebook.com/profile.php?id=100014328558284

Grumpy_Mike

Take the first code and replace the loop function of it with the loop function of the second.
Then add the
Code: [Select]
char customKey = customKeypad.getKey();
And change each
Code: [Select]
if (digitalRead(A1) == HIGH) {
    tone(8, 494, 100); // play tone 59 (B4 = 494 Hz)

with a string of
Code: [Select]

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

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

jaredm2195

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

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

Grumpy_Mike

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

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.

Grumpy_Mike

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 http://forum.arduino.cc/index.php?topic=498033.0

2) You already said:-
Quote
I understand what you are telling me to do,
So what exactly is the problem?

jaredm2195

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!!!!!!!!!!
Code: [Select]
if (digitalRead(A1) == HIGH) {
    tone(8, 494, 100); // play tone 59 (B4 = 494 Hz)

with a string of
Code: [Select]

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

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

Grumpy_Mike

Quote
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.

jaredm2195


Go Up