Hello. So I've been working on this project for a while and I got all the wiring down and the design and all I need is coding. And I beginner so I was wondering if anyone could help me with this 16 push button coding problem
How are the 16 buttons connected to your Arduino?
If it's a matrix (4x4) you could use the Keypad library.
http://playground.arduino.cc/code/Keypad
http://playground.arduino.cc/Main/KeypadTutorial
well the 4x4 is connected to Br ( Button row ) to the Breadboard
ChillLee:
well the 4x4 is connected to Br ( Button row ) to the Breadboard
That statement makes no sense. Please describe the connections in detail.
Sorry what I meant was that it is a 16 button (4x4) and I have the four button rows to my breadboard which are b5 b6 b7 b8 but I don't know if i should connect the breadboard to the analog or digital
Typically a 4x4 keypad will have 8 pins. Four are for the rows. Four are for the columns. Connect all eight to digital pins. If you run out of digital pins you can use A0-A5 as digital pins.
The keypad library I pointed to earlier does the keyboard scanning. You just have to decide what character you want to receive for each button.
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = { // This is where you define the character each key returns.
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
if (key) { // Value is 0 is no key was pressed
Serial.println(key); // Key was pressed so the character for that key was returned
}
}
Okay i tried it but it seems like 'Keypad' does not name a type
((Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS )))