Show Posts
Pages: 1 ... 13 14 [15] 16 17 ... 252
211  Using Arduino / Project Guidance / Re: Need help to splitt a string that comes from serieport on: August 20, 2014, 12:47:55 pm
Ok, so you can have this then.

Try this.

Code:
// a the top of the code, above setup()
char data[10][10]; // declared globally
byte i = 0, j = 0, idx = 0;

//within the loop()
char c = Serial.read();
if( c != '\b' || c != '\r' || c != '\n') // check if incoming char is NOT any of the 3 delimiters
{
  data[i] [j]= c;
  j++;
}
else if(c == '\n') // if the incoming char is '\n', start a counter until another(different) delimiter is found
{
  j = 0;
  idx++;
}
else if(c == '\b' || c == '\r') // if the char is '\b' or '\r', then change the array index based on the counter
{
  i = idx;
  idx=0;
}

@Robin, I was thinking that too, but I can't test it on my end to be sure. If it doesn't work as it is now, then he can change it to use &&

Quote
It looks like <CR> marks the end of each sequence
If that is true, then it will make the code a little easier.

Code:
// a the top of the code, above setup()
char data[10][10]; // declared globally
byte i = 0, j = 0;

//within the loop()
char c = Serial.read();
if( c != '\b' || c != '\r' || c != '\n') // check if incoming char is NOT any of the 3 delimiters
{
  data[i] [j]= c;
  j++;
}
else if(c == '\r') // if the incoming char is '\r', increment the index
{
  j = 0;
  i++;
}
Note: nothing in the string indicates when the code is getting new strings to split, so i++ will continue to increment = not good.
212  Using Arduino / Project Guidance / Re: Need help to splitt a string that comes from serieport on: August 20, 2014, 12:18:04 pm
You can have the code discard those delimiters. it should be as simple as

Example.
Code:
char c = Serial.read();
if( c != '\b' || c != '\r' || c != '\n') // check if incoming char is NOT any of the 3 delimiters
{
  // not a delimiter, store the char in an array
}

Now if there is a distinct pattern to the delimiters as to what comes in first and last, then you can have the code split the chars into there own index in the array, instead of them all together.
213  Using Arduino / Displays / Re: touchscreen not responding to touch on: August 19, 2014, 11:32:09 pm
I will take a look at the library in the morning and see if there is something wrong with it. If nothing is wrong then it is on your end.
214  Using Arduino / Displays / Re: touchscreen not responding to touch on: August 19, 2014, 07:36:04 pm
Code:
touchscreen does not name a type
This error means the compiler doesn't know where the library is. So where exactly is the library in the sketch folder? it should be in a folder called "libraries" which is inside the sketch folder.
215  Using Arduino / Displays / Re: touchscreen not responding to touch on: August 19, 2014, 05:30:18 pm
Where are you installing the libraries?
216  Using Arduino / Displays / Re: touchscreen not responding to touch on: August 19, 2014, 04:33:14 pm
We need to know what you have in order to help you. Links are needed!
217  Using Arduino / Project Guidance / Re: Bluetooth Module Action when Disconnected on: August 19, 2014, 04:32:26 pm
Yes, there is nothing stopping it from continuously showing "not connected" so you need to check the current state and compare it to a previous state. If the current state is different than the previous state, update the previous state and show the the connection status, otherwise don't show it.
218  Using Arduino / Programming Questions / Re: Software Serial and Servo on: August 19, 2014, 04:29:25 pm
The arduino is not able to provide the amount of power the servo needs to work. So you need to get an external power source to power the servo. Get 4xAA batteries, that should be enough. NOTE: make sure the ground ( - ) is connected to the GND pin on the arduino!
219  Using Arduino / Project Guidance / Re: Bluetooth Module Action when Disconnected on: August 19, 2014, 03:44:23 pm
Code:
boolean state;
long time = millis();

void setup()
{
  Serial.begin(115200);
  pinMode(2, INPUT);
}

void loop()

  state = digitalRead(37);
    if(state)
    {
      long tmp = millis() - time ;
     
      if(tmp > 300)
        Serial.println("    connected");
    }
    else
    {
      time = millis();
      Serial.println("Not connected");
    }
}

"Simple" sketch.
220  Using Arduino / Programming Questions / Re: Servos not working/responding, on: August 19, 2014, 03:07:55 pm
Not sure if this should be a new post or not.

How are they powered and wired?
221  Using Arduino / Programming Questions / Re: Software Serial and Servo on: August 19, 2014, 03:04:27 pm
And also take a look at this. ServoTimer2
222  Using Arduino / Programming Questions / Re: const int variable value changes?! on: August 18, 2014, 11:33:24 pm
Because it's type int, which has a value range of -32768 to 32767. Basically once the value goes past 32767, it rolls over into the negatives so 60000 - 65535(double the range) is the value you are seeing. If you make it unsigned long in which case the value range is now 0 to 65535, it won't change. Take a look at the arduino refference page to see all the types.
223  Using Arduino / Programming Questions / Re: sending a word on: August 18, 2014, 09:03:09 pm
This one is better, it will search the buffer for all the strings and show which ones it finds. If it doesn't find anything, it will show "not found".

Code:
char * strings[] = {
  "RED", "GREEN", "BLUE","ORANGE"};
 
byte i = 0, j=0;
unsigned long _startMillis = 0;
char data[20];
int index = 0;
boolean search = false, found = false;
#define arrSize(x) sizeof(x)/sizeof(x[0])

void setup()
{
  Serial.begin(115200);
  clear(20);
  Serial.println(arrSize(strings));
}

void loop()
{
  searchBuff(20);
}

void searchBuff(byte samples)
{
  if(Serial.available() > 0)
  {
    for(int S = 0, tmp; S < samples; S++)
    {
      tmp = Serial.read();
      if(tmp != '\n' || tmp != '\r' || tmp != '\0')
        data[S] = tmp;
      delay(1);
    }
    search = true;
    found = false;
  }
  index = 0;

  if(search)
  {
    j = 0;
    while(j < arrSize(strings))
    {
      for(byte i = 0; i < samples; i++)
      {
        if(data[i] != strings[j][index])
          index = 0; // reset index if any char does not match

        if( data[i] == strings[j][index])
        {
          if(index == strlen(strings[j])-1) // is true if all chars in the target match
          {
            Serial.print("Found ");
            Serial.println(strings[j]);
            index = 0;
            found = true;
            break;
          }
          else
            index++;
        }
      }//end of FOR loop
      if(found)
        search = false;
      j++;
    }// End of WHILE loop
    if(!found)
    {
      Serial.println("not found");
      search = false;
    }
   
    clear(samples);
  }// End of Search
}

void clear(byte samples)
{
  int k = 0;
  while(k < samples)
  {
    data[k] = 0;
    k++;
  }
  search = false;
}
224  Using Arduino / Programming Questions / Re: sending a word on: August 18, 2014, 03:40:15 pm
What now?
The purpose of doing it like this is so the code can have multiple passes through what came in the buffer. Every time you do a Serial.read(), it pops an int out of the buffer until the buffer is empty. If you continue to read from the buffer after it is empty, it will return -1.

It doesn't really matter what is stored as long as the code has a copy of the buffer, even if it is empty (doesn't really serve a point if it is empty though).
225  Using Arduino / Programming Questions / Re: sending a word on: August 18, 2014, 02:28:46 pm
I added the delay because it wasn't collecting everything.

I edited the code.
Pages: 1 ... 13 14 [15] 16 17 ... 252