hey i am trying to code something that would let me change values of certain variables. so far i have a enter password to unlock menu and this is the code for it. my question is how would i add a option menu after? if password is correct display menu kind of system. and how do i change value of eg. temp A or temp B to what i want through serial input
{
if( password());
bool password (){
if (Serial.available() > 0) { //wait for data available
String teststr = Serial.readString(); //read until timeout
Serial.println(teststr + "\n");
teststr.trim(); // remove any \r \n whitespace at the end of the String
if (teststr == "open") {
Serial.println("correct!");
} else {
Serial.println("wrong password, try again");
}
}}
We require you to post ALL your code and a schematic of what you have along with what your project is trying to achieve. Also what you code does against what you expect it to do.
At the moment if you do not press anything on the keyboard you will just get it printing
So this function is supposed to return a bool type variable but in fact it returns nothing because it has no return instruction in it.
None of your functions can do anything because they can never be called.
Don't vandalise your own thread, this is the code you posted:-
int Bseconds;
int Cseconds;
char rx_byte = 0;
String rx_str = "";
boolean not_number = false;
int result;
void setup() {
Serial.begin(9600);
Serial.println("enter password");
}
void loop()
{
password();
}
bool password (){
if (Serial.available() > 0) { //wait for data available
String teststr = Serial.readString(); //read until timeout
Serial.println(teststr + "\n");
teststr.trim(); // remove any \r \n whitespace at the end of the String
if (teststr == "open") {
Serial.println("correct!");
} else {
Serial.println("wrong password, try again");
}
}}
void choicemenu()
{
int menuChoice = Serial.parseInt();
switch (menuChoice) {
case 1:
// temp sensor code goes here
Serial.print("A seconds is : ");
Serial.println(Aseconds);
break;
case 2:
// humidity sensor code goes here
Serial.print("B seconds is : ");
Serial.println(Bseconds);
break;
case 3:
// pressure sensor code goes here
Serial.print("C seconds is : ");
Serial.println(Cseconds);
break;}
}
void As()
{
if (Serial.available() > 0) { // is a character available?
rx_byte = Serial.read(); // get the character
if ((rx_byte >= '0') && (rx_byte <= '9')) {
rx_str += rx_byte;
}
else if (rx_byte == '\n') {
// end of string
if (not_number) {
Serial.println("Not a number");
}
else {
// multiply the number by 1
result = rx_str.toInt() * 1;
// print the result
Serial.print(rx_str);
Serial.print(" x 1 = ");
Serial.print(result);
Serial.println("");
Serial.println("Enter a number to change value A.");
}
not_number = false; // reset flag
rx_str = ""; // clear the string for reuse
}
else {
// non-number character received
not_number = true; // flag a non-number
}
} // end: if (Serial.available() > 0)
}
void Bs()
{
if (Serial.available() > 0) { // is a character available?
rx_byte = Serial.read(); // get the character
if ((rx_byte >= '0') && (rx_byte <= '9')) {
rx_str += rx_byte;
}
else if (rx_byte == '\n') {
// end of string
if (not_number) {
Serial.println("Not a number");
}
else {
// multiply the number by 1
result = rx_str.toInt() * 1;
// print the result
Serial.print(rx_str);
Serial.print(" x 1 = ");
Serial.print(result);
Serial.println("");
Serial.println("Enter a number to chnage value B.");
}
not_number = false; // reset flag
rx_str = ""; // clear the string for reuse
}
else {
// non-number character received
not_number = true; // flag a non-number
}
} // end: if (Serial.available() > 0)
}
void cs()
{
if (Serial.available() > 0) { // is a character available?
rx_byte = Serial.read(); // get the character
if ((rx_byte >= '0') && (rx_byte <= '9')) {
rx_str += rx_byte;
}
else if (rx_byte == '\n') {
// end of string
if (not_number) {
Serial.println("Not a number");
}
else {
// multiply the number by 1
result = rx_str.toInt() * 1;
// print the result
Serial.print(rx_str);
Serial.print(" x 1 = ");
Serial.print(result);
Serial.println("");
Serial.println("Enter a number to chnage value c");
}
not_number = false; // reset flag
rx_str = ""; // clear the string for reuse
}
else {
// non-number character received
not_number = true; // flag a non-number
}
} // end: if (Serial.available() > 0)
}