Go Down

Topic: Beginner - I have problem with IF statement (Read 446 times) previous topic - next topic

cargol

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


el_supremo

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

This is wrong:
if(potenciometro > 500);

This is right:
if(potenciometro > 500)

Pete


Go Up