Thursday, 4 February 2010

Creating a loop

Had a great deal of difficulty with looping! Not much appears to be available online explaining how to do it. What i have finally managed to do is add 2 loops, which gives the solenoid a different pattern. What i have failed to do is control the number of loops it should loop...

for(int r=0; r<20; style="font-weight: bold;">set to repeat 20 times
{
if(r<10)
{
digitalWrite(solenoid, HIGH); //turn solenoid on and off every 50ms
delay(50);
digitalWrite(solenoid, LOW);
delay(50);
}
}
delay(3000); //once loop has completed 20 times wait 3 seconds

for(int s=0; s<10; style="font-weight: bold;">begin new loop to repeat 10 times
{
if(s<10)
{
digitalWrite(solenoid, HIGH); // turn solenoid on and off every 250ms
delay(250);
digitalWrite(solenoid, LOW);
delay(250);
}


delay(1000);} // once loop has completed 10 times wait 1 second
}

So this has created a sequence that continues to repeat itself infinite number of times.

No comments:

Post a Comment