#include <Keypad.h>
String inputString = ""; // a String to hold incoming data bool stringComplete = false; // whether the string is complete
const byte ROWS = 4; //four rows const byte COLS = 4; //three columns char keys[ROWS][COLS] = { {'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'},
}; byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int iAm = 1; //this is device number 1 float checkSum = 0.00; //check sum to send as serial float voltage = 5.26; //system voltage int data[20] {0, 0, 0, 0, 0, 0, 0, 0, 0}; //keypad output call char rsvp = 0; int rsvp1 = 0; void setup() { Serial.begin(9600);
inputString.reserve(200); // reserve 200 bytes for the inputString: }
void loop() {
int key = keypad.getKey();
if (key) { int key1 = key -48;
#include <Keypad.h>
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int iAm = 1; //this is device number 1
float checkSum = 0.00; //check sum to send as serial
float voltage = 5.26; //system voltage
int data[20] {0, 0, 0, 0, 0, 0, 0, 0, 0}; //keypad output call
char rsvp = 0;
int rsvp1 = 0;
void setup() {
Serial.begin(9600);
inputString.reserve(200); // reserve 200 bytes for the inputString:
}
void loop() {
int key = keypad.getKey();
if (key) {
int key1 = key -48;
if (data[key1] == 1){
data[key1] = 0;
}
else {
data[key1] = 1;
}
} // print the string when a newline arrives: if (stringComplete) { rsvp = inputString.charAt(0); rsvp1 = int(rsvp);
}
// print the string when a newline arrives:
if (stringComplete) {
rsvp = inputString.charAt(0);
rsvp1 = int(rsvp);
if (rsvp1 = iAm) {
checkSum = voltage * (iAm + data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7] + data[8] + data[9]);
Serial.print(inputString);
Serial.println(rsvp1);
Serial.print(iAm);
Serial.print("/");
Serial.print(data[1]);
Serial.print("/");
Serial.print(data[2]);
Serial.print("/");
Serial.print(data[3]);
Serial.print("/");
Serial.print(data[4]);
Serial.print("/");
Serial.print(data[5]);
Serial.print("/");
Serial.print(data[6]);
Serial.print("/");
Serial.print(data[7]);
Serial.print("/");
Serial.print(data[8]);
Serial.print("/");
Serial.print(data[9]);
Serial.print("/");
Serial.print(voltage);
Serial.println("/");
Serial.println(checkSum);
// clear the string:
inputString = "";
stringComplete = false;
}
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag so the main loop can
// do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
/*
SerialEvent occurs whenever a new data comes in the hardware serial RX. This
routine is run between each time loop() runs, so using delay inside loop can
de
if (Serial.available() > 0) {
int recieved = Serial.read();
if (recieved == iAm){
checkSum = voltage * (iAm + data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7] + data[8] + data[9]);
Serial.print(iAm);
Serial.print("/");
Serial.print(data[1]);
Serial.print("/");
Serial.print(data[2]);
Serial.print("/");
Serial.print(data[3]);
Serial.print("/");
Serial.print(data[4]);
Serial.print("/");
Serial.print(data[5]);
Serial.print("/");
Serial.print(data[6]);
Serial.print("/");
Serial.print(data[7]);
Serial.print("/");
Serial.print(data[8]);
Serial.print("/");
Serial.print(data[9]);
Serial.print("/");
Serial.print(voltage);
Serial.println("/");
Serial.println(checkSum);
}
}
}
} } void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the inputString: inputString += inChar; // if the incoming character is a newline, set a flag so the main loop can // do something about it: if (inChar == '\n') { stringComplete = true; } } }
/* SerialEvent occurs whenever a new data comes in the hardware serial RX. This routine is run between each time loop() runs, so using delay inside loop can de if (Serial.available() > 0) { int recieved = Serial.read(); if (recieved == iAm){ checkSum = voltage * (iAm + data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7] + data[8] + data[9]); Serial.print(iAm); Serial.print("/"); Serial.print(data[1]); Serial.print("/"); Serial.print(data[2]); Serial.print("/"); Serial.print(data[3]); Serial.print("/"); Serial.print(data[4]); Serial.print("/"); Serial.print(data[5]); Serial.print("/"); Serial.print(data[6]); Serial.print("/"); Serial.print(data[7]); Serial.print("/"); Serial.print(data[8]); Serial.print("/"); Serial.print(data[9]); Serial.print("/"); Serial.print(voltage); Serial.println("/"); Serial.println(checkSum); } } }