Pages: [1]   Go Down
Author Topic: Beginner - I have problem with IF statement  (Read 364 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good afternoon,

I'm making your skins a practice with an Arduino UNO.
A flashing LED varies its value relative to a poteciometro. What happens when you want the potentiometer reaches a value close to 500 (near the middle of its travel) that turns off.
I try and I try but it does not work and continuous flashing. The flashing if that varies recorido potentiometer.

The code is;

int potPin = 0; // pin entrada para potenciómetro
int ledPin = 13; // pin de salida para el LED
void setup()
{
pinMode(ledPin, OUTPUT); // declara ledPin como SALIDA
}

void loop()
{
int potenciometro = analogRead(potPin);
if(potenciometro > 500); // para apagar el led
{
digitalWrite(ledPin, HIGH); // pone ledPin en on
delay(analogRead(potPin)); // detiene la ejecución un tiempo “potPin”
}

digitalWrite(ledPin, LOW); // pone ledPin en off
delay(analogRead(potPin)); // detiene la ejecución
// un tiempo “potPin”
}


Thank you
Miquel

Logged

Offline Offline
Edison Member
*
Karma: 35
Posts: 1429
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Remove the semicolon at the end if the "if" statement

This is wrong:
if(potenciometro > 500);

This is right:
if(potenciometro > 500)

Pete
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Many, Many thanks Pete

Miquel
Logged

Pages: [1]   Go Up
Jump to: