Hola, estoy intentando que una parte de codigo se ejecute una vez sola, en este caso el "blink" que solo lo haga un par de veces
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
void loop() {
int var = 0;
while(var < 2){
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
var++;
}
}
¿El led de el pin 13, no tendria que apagarse y prenderse dos veces?
Lo que estás haciendo es asignar el valor 0 a "var" cada vez que repites el loop y, por tanto, repitiendo el blink siempre.
Pon "int var = 0;" en setup o, como dice ionhs, ponlo todo en setup.
Una forma para verlo claro es crearte el blink como una función void, por ejemplo;
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
blink();
blink();
}
void loop()
{}
void blink(){
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}