Go Down

Topic: Help me about these codes (Read 554 times) previous topic - next topic

papyrus12

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);
}

guix

#1
Oct 13, 2012, 01:26 pm Last Edit: Oct 13, 2012, 01:36 pm by guix Reason: 1
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 :)

In your code is missing a closing bracket "}", that's why indentation is useful :)

MarkT

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)!!
[ I won't respond to messages, use the forum please ]

bubulindo

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

apart from that, it should work as written.
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).

papyrus12

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.

PaulS

Code: [Select]
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!

AWOL

#6
Oct 13, 2012, 02:30 pm Last Edit: Oct 13, 2012, 02:37 pm by AWOL Reason: 1
Quote
this is the real on:

Really?
Complete with italics?

Is it so hard to post stuff between [font=Verdana][[/font]code] [font=Verdana][[/font]/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.
"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.

papyrus12

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: [Select]
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.

AWOL

#8
Oct 13, 2012, 02:45 pm Last Edit: Oct 13, 2012, 09:29 pm by AWOL Reason: 1
See reply #5
"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.

PaulS

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.

papyrus12

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

AWOL

Up there, on the left is a button labelled "Main site".
Go there, and click on the button labelled "Reference".
"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.

PeterH


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?
I only provide help via the forum - please do not contact me for private consultancy.

Nick Gammon


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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up