dear john,
I've advanced a bit with your code. I put in a 4x3 keyboard and created a ROW string with three lines starting with 0,1, and 1000.
I put a little BIP just to accompany the keyboard keys.
What I would like is: When I type 0, I see in the MonitorSerial data only from line 0 printed including 0. I then select which fields among the 5 fields each line has.
When I type 1 on the keyboard, I only see data from row 1.
And when I type 1000 I only see data from line 1000.
How would the code look to do this ?
= I'm using an ESP32 as that's what I have available here at the moment.
#include <Tone32.h>
#include <Keypad.h>
#define ROW_NUM 4
#define COLUMN_NUM 3
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte pin_rows[ROW_NUM] = {36, 39, 34, 35};
byte pin_column[COLUMN_NUM] = {32, 14, 12};
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
const int buzzer = 13;
String row =
"0,james frank gemerson,ED0,987654321,22133434536573869
1,samuel vick leman,EM1,123456789,0001234
1000,lee bronx massa,EF2,24681357,11223344556677";
String value = "";
void setup() {
Serial.begin(115200);
pinMode(buzzer, OUTPUT);
// if (row.startsWith(value + ',')) {
// ShowData(row);
// }
}
void loop() {
char key = keypad.getKey();
if (key) {
value += key;
Serial.println(value);
tone(13,440,70,0);
}
if (key == '*') {
value = "";
}
if (value == "120") {
ShowData(row);
value = "";
}
}
void ShowData(String &row) {
size_t idIndex = row.indexOf(',') - 3;
size_t idEnd = row.indexOf(',', idIndex);
String id = row.substring(idIndex, idEnd);
size_t dataIndex = row.indexOf(',', idEnd + 0) + 1;
size_t dataEnd = row.indexOf(',', dataIndex);
String data = row.substring(dataIndex, dataEnd);
Serial.println(id + ", " + data);
// size_t nameIndex = row.indexOf(',') + 1;
// size_t nameEnd = row.indexOf(',', nameIndex);
// String name = row.substring(nameIndex, nameEnd);
// size_t dataIndex = row.indexOf(',', nameEnd+1) + 1;
// size_t dataEnd = row.indexOf(',', dataIndex);
// String data = row.substring(dataIndex, dataEnd);
// Serial.println(name + ", " + data);
}