"if" statment compiling but not beeing recognized from the IDE Arduino program

I,
Sorry for this basic question, I'm very new to Arduino.

Using the soft that allows you to schedule / compile and upload to the board I've tested several times now the instruction "if" using the examples on the "programming notebook" available on the net.

Now I realize that (unfornutunaly) each command / statment has uppercase letters that are mandatory, such as "pinMode" (which "m" must be capitalized to be recognized by the IDE app ufff)

But "if" is not being recognized anyway I tried, it's "as is" in notebook notes, I really do not understand why this is happening,

Any help out there?
thanks in advance

This is "as is" in the notebook:


// Digital Input

int ledpin = 12;
int inpin=2;

void setup() {
pinMode(ledpin, OUTPUT); //# lED OUTPUT
pinMode(inpin, INPUT); //# lED OUTPUT
}

void loop() {
if (digitalRead(inpin) == HIGH) // Verify Swicht
{
digitalWrite(ledpin, HIGH);
delay(200);
digitalWrite(ledpin, LOW);
delay(200);
}
}


What makes you think the if statement is not being "recognized"? That the condition never evaluates to true is NOT sufficient proof. You almost certainly do not have the switch wired the way the author of the sketch intended.

AntonioCaldeira:
I,
Sorry for this basic question, I'm very new to Arduino.

Using the soft that allows you to schedule / compile and upload to the board I've tested several times now the instruction "if" using the examples on the "programming notebook" available on the net.

Now I realize that (unfornutunaly) each command / statment has uppercase letters that are mandatory, such as "pinMode" (which "m" must be capitalized to be recognized by the IDE app ufff)

But "if" is not being recognized anyway I tried, it's "as is" in notebook notes, I really do not understand why this is happening,

Any help out there?
thanks in advance

This is "as is" in the notebook:


// Digital Input

int ledpin = 12;
int inpin=2;

void setup() {
pinMode(ledpin, OUTPUT); //# lED OUTPUT
pinMode(inpin, INPUT); //# lED OUTPUT
}

void loop() {
if (digitalRead(inpin) == HIGH) // Verify Swicht
{
digitalWrite(ledpin, HIGH);
delay(200);
digitalWrite(ledpin, LOW);
delay(200);
}
}


What, EXACTLY, tells you the "if" is not being recognized?

Paul

Not to jump on the band wagon, but I too will start with what exactly tells you the "if statement" is not being "recognized"?

Is it the fact that nothing happens as you toggle inpin? If so, please provide detail on how you are changing the value and a drawing or picture of your wiring.

because when I type the code it does not change color and then it does not work, although it compiles an upload

connected in the right way, no problem with that.

What code doesn't change color?

Does the uploaded sketch do what you want?

no, just keep's the led blinking (sorry for the delay in replying, i'm still in the limited situation to be only able to reply each 5 minutes :-/)

What do you expect it to do? Stop blinking when inpin is LOW? If so, then it sounds like a wiring issue. Please provide detail on how you are changing the value and a drawing or picture of your wiring.

(I'll check back in 5 minutes :slight_smile: )

This is EXATLY who I did it, just like it cames on the Notebook

(just copy the link the a new page in the browser)

I cannot bring up the website (timeout error).

If it is a picture, can you edit the post and attach the picture?

Also try changing HIGH to 1.

A wild guess, you have no pull down resistor connected to that input/switch/button...

septillion:
A wild guess, you have no pull down resistor connected to that input/switch/button...

I wasn't in the mood to guess. That's why I asked for a picture and/or drawing of the wiring. I also noticed the lack of the internal pullup being enabled.

Realy I'm not doing it proprely, lets test again

I do have a pulldown resistor of 10k, as is in the "Programming notebook" page for arduino (maybe I learn later how to send pictures :-()

IF you don't use the Quick Reply but just click the Reply button you can just attach it :wink:

What is connected to:

5V:

inpin:

Gnd:

is very simple, the code you know, the circuit is a switch between +5v and the input pin, and a resistor at the pin node to the ground, very basic

even if I remove the switch, it keeps blinking the led

but the question is "why does the compile application doesn't recognize" IF "(by changing its color)?

The question is "who cares if the compiler changes the color"?

If you remove the resistor and the switch, connect a piece of wire between inpin and 5V what happens?

What happens if you connect the wire from inpin to GND?

What happens if you change HIGH to 1 and repeat the above?

is very simple, the code you know, the circuit is a switch between +5v and the input pin, and a resistor at the pin node to the ground, very basic

even if I remove the switch, it keeps blinking the led

but the question is "why does the compile application doesn't recognize" IF "(by changing its color)?

is very simple, the code you know, the circuit is a switch between +5v and the input pin, and a resistor at the pin node to the ground, very basic

even if I remove the switch, it keeps blinking the led

but the question is "why does the compile application doesn't recognize" IF "(by changing its color)? with the code right as its shown on the beguining of this topic

(and the led keeps on blinking kkkk)