Hi. I would like to define three variables via the serial monitor, they are all integers.
I would like to be able to change them at any time. And have some type of prefix so the Programm knows what integer to change.
For example if I want to define Time A as 500 I want to type "TA500" in the Serial monitor.
I know this is possible but I have no idea how it is done.
I have some bits of code from another project that does that but somehow some of it got lost and I can't finde the article where I copied it from anymore. If you could help me complete the code or get a different solution running it would be very appreciated.
Here it is:
while(Arr[j+2] != 0){
tmp[j] = Arr [j+2];
j++;
}
long int num = constrain(atol(tmp),50,65500);
if(num <= 0){
Serial.println("Error: Setting Run Time to 100 ms");
return 100;
}
return num;
}
void serialFlush(){ //Flushes Serial Buffer
while(Serial.available()) {
char t = Serial.read();
}
}
void dispenserFun(char Arr[], int len){ //Converting Input Stream into possible Functions
if(Arr[0] == 'T' && Arr[1] == 'A'){
zeit[0] = Char2Int(Arr, len);
Serial.print("Time 1: ");
Serial.print(time[0]);
Serial.println(" ms");
}
else if(Arr[0] == 'T' && Arr[1] == 'B'){
zeit[1] = Char2Int(Arr, len);
Serial.print("time 2");
Serial.print(time[1]);
Serial.println(" ms");
}
else if(Arr[0] == 'D' && Arr[1] == 'A'){
//Dispense
Serial.print("Running for ");
Serial.print(time[0]);
Serial.println(" ms");
}
else if(Arr[0] == 'D' && Arr[1] == 'B'){
Serial.print("Running for ");
Serial.print(time[1]);
Serial.println(" ms");
}
else if(strcmp(Arr,"\r\n")==0){
//Do nothing
}
else if(strcmp(Arr,"INFO\r\n")==0){
//INFO like: Serial.print("Possible tines 1:50-500 2:50-100");
}
else{
Serial.println("No command");
}
}
void setup() {
Serial.begin(9600);
//INFO like: Serial.print("Possible tines 1:50-500 2:50-100");
}
void loop() {
if(Serial.available()){
while(Serial.available() && strPointer < 50){ //reading out input stream
recData[strPointer] = Serial.read();
if ((recData[strPointer]>='a') && (recData[strPointer]<='z')) recData[strPointer]+='A'-'a'; //Kapital latters
strPointer++;
}
recData[strPointer]=0;
dispenserFun(recData, strPointer);
serialFlush();
strPointer = 0;
}
delay(1000);
}