Pages: [1]   Go Down
Author Topic: Help me about these codes  (Read 453 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How about this:

void setup(){

 int state = digitalRead(button);

if(button == HIGH){
   write();
   delay(10000);
   reply();
}

void write(){
Serial.write((byte)0x00);
Serial.write((byte)0x00);
Serial.write((byte)0x00);
Serial.write((byte)0x00);
Serial.write((byte)0x00);
Serial.write((byte)0x00);
}

void reply(){
Serial.write((byte)0x00);
Serial.write((byte)0x00);
Serial.write((byte)0x00);
Serial.write((byte)0x00);
Serial.write((byte)0x00);
Serial.write((byte)0x00);
}
Logged

France
Offline Offline
God Member
*****
Karma: 29
Posts: 898
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, please follow this advice before you are punished!!
Code tags would be good too. I do believe you've been asked before to do that.

Just write:
[ code ]<your code here>[ /code ]
(without spaces)

And, if you explained the problem it would be useful smiley

In your code is missing a closing bracket "}", that's why indentation is useful smiley
« Last Edit: October 13, 2012, 06:36:48 am by guix » Logged

0
Online Online
Shannon Member
****
Karma: 162
Posts: 10473
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So the way to enable people to help you is to explain your problem.  This means saying

1) What you want to accomplish - we are lacking this
2) What is actually happening (and why this is wrong)  - we are lacking this
3) Show all relevant information - you seem to have done this (apart from lack of code tags).

Usually people fail on 2) and 3), not on 1)!!
Logged

[ I won't respond to messages, use the forum please ]

'round the world...
Online Online
Faraday Member
**
Karma: 41
Posts: 3113
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

you are using button when you should be using state...

apart from that, it should work as written.
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Offline Offline
Newbie
*
Karma: 1
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, sorry about the lack of information. Sorry but I don't have the codes right now, just brainstorming about what I want to do.

First, I want a command that will write a data to the serial and that command is the switch, if the switch send a logic high, the writing of data to the serial will be followed. Then another set of data will be followed.

Second, about the void reply, it is wrong, typographical error.

this is the real on:
byte RxData[8];
int i;

if(Serial.available()>0){
 for(i=0; i<8; i++){
 RxData = Serial.read();
 Serial.print(RxData, HEX);
}

if(RxData[4] == 0x05){
  Serial.print("Hello User);}
else{
 Serial.print("No User profile");
}


Third, I call that data in the RxData[8], but I'm getting zero,

The problem is about the RxData, like it doesn't store data at all.
Logged

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

Code:
if(Serial.available()>0){
 for(i=0; i<8; i++){
 RxData = Serial.read();
If there is at least one byte available to read, read all 8 of them. Nope. FAIL!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24433
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
this is the real on:
Really?
Complete with italics?

Is it so hard to post stuff between [code] [/code] tags?
How many times is it now you've been asked for this simple courtesy?

There are a few really good reasons we ask you to post properly, and you've demonstrated one of them very well.
« Last Edit: October 13, 2012, 07:37:30 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 1
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Fine, I will follow ALL YOUR DIRECTION CORRECTLY but ANSWER ALL MY QUESTIONS CORRECTLY WITHOUT ANY TRASH TALK.
I know that I am a noob here and I am approach a master or god for help, so please be considerate.

Code:
if(Serial.available()>0){
for(i=0; i<0; i++){
RxData[i] = Serial.read();
Serial.print(RxData[i], HEX);
}
}

This only reads the data not storing it, so please kindly help me.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24433
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

See reply #5
« Last Edit: October 13, 2012, 02:29:27 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

If you KNOW that you need to read 8 bytes, you must not do so until there are at least 8 bytes to read. Look at the documentation for the Serial.available() method. You will see that, despite your usage (which I abhor) that it is NOT a boolean function.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you. Can you give some sites or pages about this serial.available documentations.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24433
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Up there, on the left is a button labelled "Main site".
Go there, and click on the button labelled "Reference".
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11195
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ANSWER ALL MY QUESTIONS CORRECTLY WITHOUT ANY TRASH TALK.

You are asking strangers to expend their time and attention helping you, and offering nothing in return. Do you think that the attitude you're showing here is going to encourage them to do that?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Fine, I will follow ALL YOUR DIRECTION CORRECTLY but ANSWER ALL MY QUESTIONS CORRECTLY WITHOUT ANY TRASH TALK.

No, you don't follow the directions.

http://arduino.cc/forum/index.php/topic,126907

You have been asked repeatedly to put your code into code tags, and you just ignore us. Now you are shouting insults. Stop it.
Logged

Pages: [1]   Go Up
Jump to: