Hello everyone !
Can anyone help me, i have a problem with my coding. The coding should be able to print out the name and the price of the product, but the thing is the keypad won't allow me to type the code properly and thus it won't print the price and the product on serial monitor. Can anyone point out my mistakes or error in this coding ?
I don't know how to upload the coding properly so i just copy it to here.
Thank you in advanced
`
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the kpd
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const String bebidas [] = {"A35", "A36", "A37", "A38", "A39", "A40"};
String input_codigo;
float precio;
String refresco = " ";
void setup() {
Serial.begin(9600);
input_codigo.reserve(32); // maximum input characters is 33, change if needed
}
void loop() {
productos(&precio,&refresco);
Serial.print("Has elegido:");
Serial.println(refresco);
Serial.print(precio);
Serial.println("€");
delay(1000);
}
// elegir el producto
void productos (float *p, String *r)
{
char key = keypad.getKey();
if (key) {
Serial.print(key);
input_codigo += key;
if (input_codigo.length() == 3) {
if (input_codigo == bebidas[0]) {
*p = 1.5;
*r = "un refreco de cola";
/Serial.println(" ");
Serial.println("Has elegido:");
Serial.print("precio:");
Serial.print(precio);
Serial.println("€");/
}
else if (input_codigo == bebidas[1]) {
*p = 1.5;
*r = "un refreco de naranja";
/Serial.println(" ");
Serial.println("Has elegido un refresco de naranja");
Serial.print("precio:");
Serial.print(precio);
Serial.println("€");/
}
else if (input_codigo == bebidas[2]) {
*p = 1.5;
*r = "un refreco de limón";
/Serial.println(" ");
Serial.println("Has elegido un refresco de limón");
Serial.print("precio:");
Serial.print(precio);
Serial.println("€");/
}
else if (input_codigo == bebidas[3]) {
p = 2.5;
r = "un zumo";
/ Serial.println(" ");
Serial.println("Has elegido un zumo");
Serial.print("precio:");
Serial.print(precio);
Serial.println("€");/
}
else if (input_codigo == bebidas[4]) {
*p = 1.25;
*r = "un agua con gas";
/Serial.println(" ");
Serial.println("Has elegido un agua con gas");
Serial.print("precio:");
Serial.print(precio);
Serial.println("€");/
}
else if (input_codigo == bebidas[5]) {
*p = 1.0;
*r = "un agua mineral";
/Serial.println(" ");
Serial.println("Has elegido un agua mineral");
Serial.print("precio:");
Serial.print(precio);
Serial.println("€");/
}
else {
Serial.println(" ");
Serial.println("no disponible, intentalo otra vez");
}
input_codigo = ""; // clear input password
}
}
}`