We have completed the Arduino sketch to blink an LED according to the Fibonacci Sequence. We used three variables to create the sequence and keep track of how far into the sequence the Arduino is at any time.
Source code posted below:
int led = 13;
int count1 = 0;
int count2 = 1;
void setup() {
pinMode(led, OUTPUT);
}
void loop()
{
for (int i = 0; i < count1; i = i + 1)
{digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
}
int temp = count2;
count2 = count1 + count2;
count1 = temp;
delay (1000);
}
No comments:
Post a Comment