//Menu display options
//1.Change IDs
//2.Collect data <--Temperature sensor
//3.Interrupt driven program <--clock which displays
//4.Access log <--Admin access only
//5.Logout
#include <EEPROM.h>
bool sendit=false;
String input="";
String inputString="";
uint16_t Empty_Addr = 1;
uint16_t EEPROM_Empty_Addr = 0;
const uint16_t VALID_IDS = 9; //number of IDs that will be saved
uint32_t idTable[VALID_IDS] = {998877665, 102350244, 102579159, 123456789, 456789123, 987654321, 10,11,56}; //saved/stored valid IDs
void setup() {
Serial.begin(115200);
Serial.println("Write number in Serial monitor:");
}
void loop() {
getInput();
}
void getInput(){ //saves and formats input from serial monitor
if (sendit == true) {
sendit = false; //prevents continuous looping
input = inputString; //copy input string
Serial.print("Inputted variable is: ");
Serial.print(input);
//writes new message to eeprom and displays from eeprom to serial monitor
save2eeprom();
String code="EEE20003";
if (input=="EEE20003\n"){
Serial.println("success");
} else {
Serial.print("fail:"); Serial.print(input);
Serial.print("code:"); Serial.print(code);
}
inputString="";//reset inputString ready for next input
}
}
void serialEvent() { //reads input from serial monitor (spaces not included)
char key;
while (Serial.available()) {
// get the new byte:
char key = (char)Serial.read(); //read any input char
inputString += key; //add current key to inputString
/* if the incoming character is a newline, set a flag so the main loop can
do something about it:*/
if (key == '\n') { //when enter is pressed
sendit = true; //save and format inputted variable
}
}
}
void save2eeprom(){
if (EEPROM.read(EEPROM_Empty_Addr))
{
for(int i = 0; i < VALID_IDS; i++)
{
EEPROM.put(Empty_Addr, idTable[i]);
Empty_Addr += sizeof(uint32_t);
EEPROM.put(EEPROM_Empty_Addr, false);
}
}
}