Wrong example i think..

Boolean Operators
These can be used inside the condition of an if statement.
&& (logical and)
True only if both operands are true, e.g.
if (digitalRead(2) == HIGH && digitalRead(3) == HIGH) { // read two switches
** // ...**
}
is true only if both inputs are high.

I just lost 2 hours figuring out why the && that i used like in this example didn't work.

This is my line of code and it wouldn't get accepted because it needed double brackets..:
if ((ch1 < 1400) && (m < 2)){ //Mower Mode ON

So why is the example from the tutorial only using single brackets and not double?? My Arduino won't accept it without double brackets and also didn't help me fixing it. Points of improvement i think.

And why do i have to wait 5 minutes before i can save my post without typo's? i only corrected some typo's but have to wait before i can save it...i only posted this, nothing else...

and it won't get accepted

What does that mean?

AWOL:
What does that mean?

That if i click on verify i get the error: "expected identifier before "(" token...

So my program won't work, i have to correct it first before uploading. While i do exactly the same as in the reference example.

Please post the code you say doesn't compile.

What version of the Arduino IDE are you using?

I wonder is this another example of "improvements" to the IDE?

However I can't check because you have not posted your program.

...R

I know it is a PITA, but you have to have 100 post's before the 5 minute delay goes away.
It's used to eliminate spam.
I'm almost there.

if (ch1 < 1400) && (m < 2){ //Mower Mode ON

This line is the same but with single brackets like in the reference...it won't get accepted like this but luckily i'm good with google and found the answer somewhere out of the arduino-site...

Why do i always have stupid issues like this? Also on the Roboteq website i posted many issues with their bad manuals. I lost months of time because of that.

Robin2:
What version of the Arduino IDE are you using?

I wonder is this another example of "improvements" to the IDE?

However I can't check because you have not posted your program.

...R

Version 1.6.12

All those different versions confused me a lot as well. Now my software likes to tell me there are new versions available but when i click on that message it says i already have the latest version with new libraries, so why it has to come up with that message?

If you want to see the whole program than it's here..but it's under development...It's for a robot which can do lawnmowing and floorsweeping and has a watercanon and some more features.

I needed the && because when i turn on the switch on the rc transmitter it has to switch some relays. One relay has to be ON for 1 second and than turned off before the next relay is turned on which powers the motor.

That's why i needed this && function, i couldn't get it programmed by if-then-else so started looking for other ways. The Switch'-Case function should also be able to do something like that but with the reference i couldn't get it to work...still don't know why. The reference needs more examples for every new function to learn. I wonder how a kid can ever learn from that, i'm not a nativ english speaker and that's another issue which makes is harder..

const int firstRelay = 9; //actuator up = J9
const int secondRelay = 10; //actuator down = J10
const int thirdRelay = 11; // contact Mower = J7
const int fourthRelay = 6; // Mower Motor ON = J8

int ch1; // Here's where we'll keep our channel values
int m; //m is the mowermode

void setup() {
pinMode(firstRelay, OUTPUT);
pinMode(secondRelay, OUTPUT);
pinMode(thirdRelay, OUTPUT);
pinMode(fourthRelay, OUTPUT);

pinMode(5, INPUT); // 5= pwm-signal in from rc receiver

Serial.begin(9600);

}

void loop() {

ch1 = pulseIn(5, HIGH); // Read the pulse width of pin 5

if(ch1>1600){ //Mower mode is OFF
m=1;
digitalWrite(firstRelay,LOW); //actuator up is ON
digitalWrite(secondRelay,HIGH); //actuator down is OFF
digitalWrite(thirdRelay,HIGH); //mowercontact is OFF
digitalWrite(fourthRelay,HIGH); //Mower Motor OFF

}
if (ch1 < 1400) && (m < 2){ //Mower Mode ON
digitalWrite(firstRelay,HIGH); // actuator UP is OFF
delay(2000);
digitalWrite(secondRelay,LOW); //actuator down is ON
digitalWrite(thirdRelay,LOW); //mowercontact is ON
delay(2000);
digitalWrite(thirdRelay,HIGH); //mowercontact is OFF
digitalWrite(fourthRelay,LOW); //Mower Motor is ON
m=m+1;
}

}

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Your original code:

E_rik:

if (ch1 < 1400) && (m < 2){   //Mower Mode ON

Is not the same as the example:

if (digitalRead(2) == HIGH  && digitalRead(3) == HIGH) { // read two switches

The if statement needs to be enclosed in brackets. Your revised code:

E_rik:

if ((ch1 < 1400) && (m < 2)){   //Mower Mode ON

is fine but this would work just as well:

if (ch1 < 1400 && m < 2){   //Mower Mode ON

Do you see that that's the exact analog of the code in the example?

Yes Pert, i see it now...thanks! If your example was in the reference as well i would have done it right the first time i guess. More examples is what i miss (so i can steal them).

It's (by the looks of it) because you just start to learn C/C++. Maybe a book (or one of the many tutorials on the web) on C will help you.

Out of curiosity, what was your thinking when you wroteif (ch1 < 1400) && (m < 2)    //Mower Mode ON

Maybe for a number of us it's simple; you could have replaced the digitalReads by ch1 and m respectively and the == HIGH by <1400 and <2 respectively and it would have compiled. I guess you made a mistake there, it did not compile and you started to 'panic' and try all kind of things :wink:

My rule is that if in doubt with multiple conditions in e.g. an if, always use extra sets of () and make sure that they are in the right place. I think the IDE helps, if you place the text cursor on e.g. a '(', it will highlight (not very clearly I thing) the matching ')',

PS
Wait till you have code that compiles but does not do what you think you told it to do :smiley:

If your example was in the reference as well i would have done it right the first time

perts example is exactly the same as the example in the reference whilst your code with single brackets is not the same.