Quick one

Happy new year to all first of all.

I'm going through some code to expand my knowledge past the arduino first timer code and have come across two occasions were I could do with a bit of your expertise :slight_smile:
Here goes

  1. sendMSG - can anyone explain this one to me?

  2. going through some code for rs485 communication I came across the following line any idea what the ! is for?

state2=!state2;

Let me apologise just in case these questions are easy to answer but I have been going through all my notes google etc and can't find anything :frowning:

Thanks in advance

Mark

  1. sendMSG - can anyone explain this one to me?

In what context? We had to lay off the psychic. Budget problems, you know.

any idea what the ! is for?

It's the not operator. It sets state2 to the state that is was not set to before. If state2 was true, it becomes false. If it was false, it becomes true.

Let me apologise just in case these questions are easy to answer

Easy is good.

PaulS many thanks for your reply!

The following is the section of code the sendMSG appears;

if (times_repeat<4){
Serial.flush();
//(byte address1,byte address2,byte data_type,byte code1,byte code2,byte Sign,byte data1,byte data2,byte data3,byte data4)
if (digitalRead(8)==HIGH){
sendMSG(48,49,68,48,48,32,48,48,48,49);
}else {
sendMSG(48,49,68,48,48,32,48,48,48,48);
}
times_repeat=times_repeat+1;

The full code is available here:

Thanks again!

Mark

The following is the section of code the sendMSG appears;

The sendMsg() line is a function call, like analogRead(), Serial.read(), etc. The function must be defined somewhere else.

The sendMsg() line is a function call, like analogRead(), Serial.read(), etc.

Correction: analogRead() is a function call, Serial.read() is a method call as read() is a method of the Serial object.

Thanks guys!

I will digest that, and carry on deciphering the code! Many thanks again!

Mark

majenko:

The sendMsg() line is a function call, like analogRead(), Serial.read(), etc.

Correction: analogRead() is a function call, Serial.read() is a method call as read() is a method of the Serial object.

If you're going to correct someone, you should probably do it correctly :slight_smile:

Last I checked, C++ doesn't have methods. It has member functions. And functions are members of classes, not objects. Objects are instances of classes. The reason this matters, in turn, is that some dynamic languages do allow methods added to objects (and also typically call them methods). C++ isn't one such language, though.