This is an old revision of the document!
In progress…
You can also define the delays using variables and loops to make things more interesting:
// now we've added two variables to hold our
// on and off time delays
// the "int" variable is able to hold integer values
int on_time;
int off_time;
void setup()
{
pinMode(1, OUTPUT); //LED on Oak
}
void loop()
{
// the for() loop will initialize a new temporary variable, i
// it runs until i >= 500, adding 50 each time
for(int i = 0; i < 500; i = i+50)
{
// the on time will equal i (0, 50, 100, ...)
on_time = i;
// the off time will equal 500 - i (500, 450, 400, ...)
off_time = 500 - i;
digitalWrite(1, HIGH);
delay(on_time);
digitalWrite(1, LOW);
delay(off_time);
}
}
Here is what happens each time the loop runs:
| time through loop | i | on_time | off_time |
|---|---|---|---|
| 1 | 0 | 0 | 500 |
| 2 | 50 | 50 | 450 |
| 3 | 100 | 100 | 300 |
| . | . | . | . |
| . | . | . | . |
| 10 | 450 | 450 | 50 |
When the for() loop above runs, i is equal to 0. It calculatesIf you upload this code, you will see this (click for enlarged view in new tab):
Congratulations! You've taken your first steps with the Oak. Take a look at some of the other tutorials for more!