AWOL:
As suggested by PeterH, I've changed some of the code
No, you didn't change it as he suggested. Read the post again, particularly around the reading of the serial port.
If the character read is global and therefore persistent, then once read, it will trigger the appropriate action every time through "loop ()" until a new character is read.
Holy crap!! I feel so stupid for the mistake I've done.. I'm sorry! now it works!!!!
Here is the sketch!
//includes necessary libraries
#include <......>
//Some setup & variables/constants declaration & other stuff
char ch=0; //global variable for Serial.read()
void setup() {
Serial.begin(9600);
//arduino/sensor setup and other stuff
}
void loop(){
if(Serial.available()){
ch=Serial.read();}
switch(ch)
{
case '1':
SHT1();
break;
case '2':
SHT2();
break;
case '3':
Pres();
break;
case '4':
LIGHT1();
break;
case '5':
LIGHT2();
break;
}
}
void SHT1(){
// do measurement and return ONE DATA
}
void SHT2(){
// do measurement and return ONE DATA
}
void Pres(){
// do measurementS and RETURN DATA AS LONG AS USER PRESS ONE KEY TO STOP MEASUREMENT
}
void LIGHT1() {
// do measurement and return ONE DATA
}
void LIGHT2() {
// do measurement and return ONE DATA
}
Is it a correct way adding "ch=0;" inside a case to get only a value from the selected case?
something like this:
case '1':
SHT1();
ch=0;
break;
Thank You all very very much!!!