Go Down

Topic: Textfinder library (Read 844 times) previous topic - next topic

thomas-h

I have used the example given in the textfinder library and changed it slightly but when ever I send a 1 it does not work ??

Code: [Select]

#include <TextFinder.h>

TextFinder  finder(Serial); 
const int NUMBER_OF_FIELDS = 3; // how many comma seperated fields we expect                                           
int values[NUMBER_OF_FIELDS];   // array holding values for all the fields

void setup()
{
  Serial.begin(115200); // Initialize serial port to send and receive at 115200 baud

  // Set up pins
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
}

void loop()
{
  if(Serial.available())
  {
    getData();
   
    int lights = values[2];
   
    if(lights == '1')
    {
      digitalWrite(9, HIGH);
    }
    else
    {
      digitalWrite(9, LOW);
    }
   
    analogWrite(11, values[0]);
    analogWrite(10, values[1]);
   
  }
}

  void getData()
  {
    if(Serial.available())
    {
      int fieldIndex = 0; // the current field being received
      finder.find("I");   
      while(fieldIndex < NUMBER_OF_FIELDS)
        values[fieldIndex++] = finder.getValue();
      //for(fieldIndex=0; fieldIndex < NUMBER_OF_FIELDS; fieldIndex++)
      //Serial.println(values[fieldIndex]);
    }
  }


When I send:
Code: [Select]
I 255,255,1 /n
It does not work.

Thanks for any help

PaulS

Quote
I have used the example given in the textfinder library and changed it slightly but when ever I send a 1 it does not work ??

So, you commented out the code that actually prints the data obtained. Why was that?

thomas-h

Because I don't need it to print the data. I just need to use it

PaulS

Quote
Because I don't need it to print the data. I just need to use it

Then, you don't have a problem?

thomas-h

Just tried sending
Code: [Select]
I 255,255,1 /n
with this code

Code: [Select]

#include <TextFinder.h>

TextFinder  finder(Serial); 
const int NUMBER_OF_FIELDS = 3; // how many comma seperated fields we expect                                           
int values[NUMBER_OF_FIELDS];   // array holding values for all the fields

void setup()
{
  Serial.begin(115200); // Initialize serial port to send and receive at 115200 baud

  // Set up pins
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
}

void loop()
{
  if(Serial.available())
  {
    getData();
   
    int lights = values[2];
   
    Serial.print(values[2]);
   
    if(lights > 0)
    {
      digitalWrite(9, HIGH);
    }
    else
    {
      digitalWrite(9, LOW);
    }
   
    analogWrite(11, values[0]);
    analogWrite(10, values[1]);
   
  }
}

  void getData()
  {
    if(Serial.available())
    {
      int fieldIndex = 0; // the current field being received
      finder.find("I");   
      while(fieldIndex < NUMBER_OF_FIELDS)
        values[fieldIndex++] = finder.getValue();
      //for(fieldIndex=0; fieldIndex < NUMBER_OF_FIELDS; fieldIndex++)
      //Serial.println(values[fieldIndex]);
    }
  }


But on the serial monitor it says 5 and not 1 ?

PaulS

#5
Mar 27, 2012, 08:11 pm Last Edit: Mar 27, 2012, 08:12 pm by PaulS Reason: 1
Code: [Select]
     //for(fieldIndex=0; fieldIndex < NUMBER_OF_FIELDS; fieldIndex++)
     //Serial.println(values[fieldIndex]);

What would these show, if they weren't commented out?

Also, try sending something like:
I 123, 456, 7 <cr><ln>

Perhaps a clue will present itself.

thomas-h

Thanks
I have now realised its my program I'm using to send the Arduino data that's wrong.

Thanks for the help

thomas-h

My program was sending a number with a decimal place and the textfinder library thought it was the end of the number.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy