Offline
Newbie
Karma: 0
Posts: 28
|
 |
« on: March 14, 2013, 03:44:16 am » |
can u please give me a sample that are receiving a serial data,that f the mcu receive a charater 'a' the corresponding data will store in a buffer and when the character 'b' is detected d corresponding character will store to other buffer..can u please give me a related sample
|
|
|
|
« Last Edit: March 14, 2013, 04:10:16 am by nehj »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: March 14, 2013, 05:35:43 am » |
if (Serial.available ()) { int inChar = Serial.read (); switch (inChar) { case 'a': // do something break; case 'b': // do something else break; default: // do something completely else } }
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #2 on: March 14, 2013, 07:56:26 am » |
The code I gave you is just an incomplete example - you need to fill in the blanks, or you could rewrite as, say, a simple state machine. You original question wasn't specific.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #3 on: March 14, 2013, 08:02:42 am » |
ah...i know that it is incomplete i just want to know if it is applicable to what i want to do?tnx
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #4 on: March 14, 2013, 08:32:30 am » |
the char 0999999999 will be save to a buffer Which ONE key did you press to type the character 0999999999?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #5 on: March 14, 2013, 08:46:55 am » |
one key??i want to store it in a buffer...this character will be send by the computer to the arduino,if ahm..for example the original data is a099999bTYYYYU, IF character 'a' is detected the 099999 will be store to a buffer and if character 'b' is detected the TYYYYU will be store to another buffer....please help me to do this...
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #6 on: March 14, 2013, 08:50:45 am » |
Proper use of capital letters and punctuation would really be appreciated here. You sound like a little boy whining.
You keep saying you want to store A character, and then you say that the character is 0999999999.
Well, I have news for you. 0999999999 is not a character. It is a string.
If you want to ask about how to read characters, and store them in an array AS A string, then say that. Don't keep referring to 0999999999 as a character.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #7 on: March 14, 2013, 08:59:47 am » |
i'm so sorry for that....im unfamiliar with this,,, ahm..is it possible to use the switch case function??plz help me
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #8 on: March 14, 2013, 09:01:05 am » |
I've shown you how to wait for and read one character into one particular buffer called "inChar", and make a decision based on the value of that character. It isn't a great leap of imagination to read in further characters and read them into other buffers.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #9 on: March 14, 2013, 09:09:41 am » |
how can i do this?any advice?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #10 on: March 14, 2013, 09:32:23 am » |
Some application, a little effort, and maybe work through some of the examples supplied in the IDE.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #11 on: March 14, 2013, 09:36:10 am » |
plz...give me a specfic examples
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #12 on: March 14, 2013, 09:37:43 am » |
It's been a while since I looked at the IDE supplied examples, but I'm pretty sure there's (at least) one on serial comms, and another on arrays. I'd start with those.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #13 on: March 14, 2013, 09:52:53 am » |
please give me the very specific examples in IDE pls???
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #14 on: March 14, 2013, 10:03:20 am » |
I'm posting from my tablet, so I'm afraid I can't. What did you do to help yourself in the fifteen minutes between my last post and yours?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
|