Hi,
This is an example to discuss on.
int led = 13;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
Label1:
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
Label2:
digitalWrite(led, HIGH);
delay(2000);
digitalWrite(led, LOW);
delay(2000);
}
I want arduino to repeat Label1 for 10 times and Label2 for 5 times.Is it possible to jump between labels with repeat times?
system
July 5, 2013, 10:16pm
2
For loops?
(Of course, we don't encourage the use of delay)
system
July 5, 2013, 11:09pm
3
It's extremely rare that a GoTo is the best way to tackle a problem and this is certainly not a problem that requires it. I suggest you try and forget that the goto command exists, and learn how to use the control expressions provided by 'C'/C++. In this case it sounds as if all you need would be a couple of for loops.
(you should read the blink without delay example, skipped for now)
try this, do the blink in a separate function and use a for loop or a while loop (used both of them as example)
int led = 13;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
for (int i=0; i<10; i++)
{
blinkLed(led, 1000);
}
int p = 0;
while(p < 5)
{
blinkLed(led, 2000);
p++;
}
}
void blinkLed(int pin, int duration)
{
digitalWrite(pin, HIGH);
delay(duration);
digitalWrite(pin, LOW);
delay(duration);
}