You are on page 1of 2

//while

int pot = A0;


int led = 5;
int datos = 0;

void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(pot, INPUT);
}

void loop() {
Serial.print("datos fuera del while= ");
Serial.println(datos);
datos = analogRead(pot);
while (datos < 500) {
Serial.print("Datos dentro del While= ");
Serial.println(datos);
digitalWrite(led, HIGH);
datos = analogRead(pot);
digitalWrite(led, LOW);
delay(500);
}
}

//do while
int pot = A0;
int led = 9;
int datos = 0;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
int potValue;
do{
potValue = analogRead(pot);
int brightness = map(potValue, 0, 1023, 0, 255);
analogWrite(led, brightness);
delay(10);
}
while (potValue > 5 && potValue < 1018);
}
// for
int pot=A0;
int led=5;
int datos=0;
void setup()
{
pinMode(led, OUTPUT);
}
void loop() {
int potValue;
int minPotValue = 5;
int maxPotValue = 1018;
for (; (potValue = analogRead(pot)) > minPotValue && potValue < maxPotValue;
delay(10)) {
int brightness = map(potValue, 0, 1023, 0, 255);
analogWrite(led, brightness);
}
}

You might also like