Pages: [1]   Go Down
Author Topic: ERROR  (Read 289 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not too knowledgeable about string...i want to recieve data,sending by the pc,and if the start of the data is d it will store to char num,????plz help me!!1
Code:
while (Serial1.available()>0){
      d=Serial1.read();
      if (d=='a'){String.toCharArray(num, 11);}
     
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49301
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What, exactly, are you trying to get into num? You've read ONE character from the serial port. You do not have a String instance. Even if you didn't, you haven't populated it with data from the serial port.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 484
Posts: 18768
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How to use this forum


* Post all your code please.
* Make a meaningful subject description (not just "ERROR").
* Don't use all caps in the subject.
* If you got an error, what is it?
Logged


North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 70
Posts: 2171
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you see the posts in your last thread: http://arduino.cc/forum/index.php/topic,150807.0.html

Quote
if the start of the data is d

there is only 1 character, and yes it is d but you check weather it is 'a'

String.toCharArray(num, 11);

String is not a variable, this line is not valid.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i am wrong to my question...i am trying to store data from pc to arduino store it in a num...if the start is 'a ' the following number will be store to num...
Code:
while (Serial1.available()>0){
      d=Serial1.read();
      if (d=='a'){String.toCharArray(num, 11);}
     
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 70
Posts: 2171
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

String.toCharArray(num, 11);

That is wrong, stop using it, delete it.

'd' has only read one character, which 'following number' do you expect to store in num.

You are looping as long as there is data:

Code:
Serial1.available() > 0

But you do not do anything with it unless it is 'a'

and there is no end '}' on your loop.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wat must be my code????
Logged

Pages: [1]   Go Up
Jump to: