Go Down

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


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


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

This is wrong:
if(potenciometro > 500);

This is right:
if(potenciometro > 500)

Don't send me technical questions via Private Message.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131