Pages: [1]   Go Down
Author Topic: Textfinder library  (Read 675 times)
0 Members and 1 Guest are viewing this topic.
Derbyshire, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
I 255,255,1 /n
It does not work.

Thanks for any help
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 651
Posts: 50845
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Derbyshire, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 651
Posts: 50845
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Because I don't need it to print the data. I just need to use it
Then, you don't have a problem?
Logged

Derbyshire, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#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 ?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 651
Posts: 50845
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
     //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.
« Last Edit: March 27, 2012, 01:12:54 pm by PaulS » Logged

Derbyshire, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thanks for the help
Logged

Derbyshire, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: