But I have one other question, though.
I have a subroutine for getting sensor-readback (I have 8 identical sensors in the system) like this :
void readSensor(int Sensor)
{
delay(1);
if (debug == true)
{
Serial.print ("Reading sensor ");
Serial.print (Sensor);
Serial.println (": ");
}
if (mySensors[Sensor] == 1)
{
Wire.beginTransmission(address); // Begin communication with TC74
if (Wire.endTransmission () == 0)
{
Wire.send(0x00); // Ask TC74 for its temperature
Wire.endTransmission();
Wire.requestFrom(address, 1); // Request 1 byte
while(Wire.available() < 1); // Wait for byte to arrive
int data = Wire.receive(); // Get byte
myReadings[Sensor] = data; // Store the reading in an array
}
if (Wire.endTransmission () != 0)
{
if (debug == true)
{
Serial.print ("Sensor not responding!!");
Serial.println ();
}
myReadings[Sensor] = -255;
}
}
else
{
if (debug == true)
{
Serial.print ("Sensor not present. Skipping...");
Serial.println ();
}
myReadings[Sensor] = -255;
// just skip this one
}
}
It's doing what it's supposed to do. In standalone-mode it just loops through all sensors and printing the readings to an LCD.
I just want to be able to pause the reading-loop and do some direct measurements by setting the program in manual-mode by sending it a specific command. I'm also able to do so, but not the way I want to.
Here's how I do it know :
void serial_listen()
{
while (Serial.available())
{
delay(10); //small delay to allow input buffer to fill
char c = Serial.read(); //gets one byte from serial buffer
// if (c == ',') {
// break;
// } //breaks out of capture loop to print readstring
readString += c;
} //makes the string readString
if (readString.length() >0) {
// Serial.println(readString); //prints string to serial port out
String inString = readString.toUpperCase();
action(inString);
readString=""; //clears variable for new input
}
}
void action(String inString)
{
if (inString == "MANUAL")
{
standAlone = false;
// Serial.print ("Stand Alone mode: ");
// Serial.println (standAlone, BIN);
lcd.clear();
lcd.cursorTo(2,8);
lcd.print("REMOTE");
lcd.cursorTo(3,7);
lcd.print("OPERATION");
Serial.println ("Going into manual mode. Please wait...");
delay(2000);
Serial.println ("Master!! Your wish is my command. I'm listening...?");
}
else if (inString == "STANDALONE")
{
if (standAlone != true)
{
standAlone = true;
Serial.println ("I'm leaving you now. Bye!!");
Serial.println ("Resuming scan. Please wait...");
lcd.clear();
lcd.cursorTo(2,4);
lcd.print("Resuming scan.");
lcd.cursorTo(3,5);
lcd.print("Please wait...");
delay(2000);
init_disp();
}
}
else if (inString == "GETSENSOR_0")
{
if (standAlone == false)
{
DEMUX(1);
selectSensor(0);
readSensor(0);
DEMUX(0);
Serial.println (myReadings[0]);
}
else Serial.println ("Must be en manual mode to execute commands!");
}
else if (inString == "GETSENSOR_1")
{
if (standAlone == false)
{
DEMUX(1);
selectSensor(1);
readSensor(1);
DEMUX(0);
Serial.println (myReadings[1]);
}
else Serial.println ("Must be en manual mode to execute commands!");
}
/* -------------- and so on for 8 sensors... ------------------- */
else
{
if (standAlone == false)
{
Serial.print ("Unknown command: ");
Serial.println (inString);
}
else Serial.println ("Must be en manual mode to execute commands!");
}
}
I'd like to "talk" directly to the void readSensor from the terminal by just typing, say :
getsensor(1)
and let the program scan the incoming string and firstly recognize the command "getsensor" and secondly getting the integer from the string and passing it to readSensor(1), and thereby get the value for sensor 1.
I know I can do it in the environment I use at work by doing :
if (index(inString, "getsensor")) {
int i = substr(inString,11);
i = trim(1,1);
readSensor(i);
}
or something like that. My apologies - it's getting late overhere, and I'm not thinking anymore...
I know I kan do substr and trim (not sure about the syntax yet, but I will be when I get there) but I'm not sure about the index part... ?