Go Down

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

jaredm2195

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);
}
}

Grumpy_Mike

That is the sort of thing.
However the
Code: [Select]
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.

jaredm2195

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?


jaredm2195

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

polymorph

This seems like a topic for "Programming Questions" or "Project Guidance".

Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Grumpy_Mike

Quote
How would I use it for when no key is pressed? Would I just leave it the way it is
Yes.

You could also make the tone for a fixed amount of time instead of leaving it to run forever. With a medium fixed time the tone would sound for say a second and yet when other keys are pressed it will override the current tone.



Go Up