We did coding to make the LED blinks in Fibonacci sequence(0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...). Below is a sketch of figuring out the reasoning behind to make it work and the code.
/*
Daniel Galan, Chip Dong Lim
DES387 Spring 2014, Professor Dominic Muren
Blink fibonaccilly.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led1 = 13;
int blinkNum;
int firstNum = 0;
int secNum = 1;
int thirdNum;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led1, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// 0 + 1 = 1; 1 + 1 = 2; 1 + 2 = 3; ...
thirdNum = firstNum + secNum;
for (int blinkNum = 0; blinkNum < thirdNum; blinkNum++) { // for blinking LED in fibonacci sequence
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led1, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for 1.5 second
}
delay(3000);
firstNum = secNum; // firstNum = 1; firstNum = 1; firstNum = 2;
secNum = thirdNum; // secNum = 1; secNum = 2; secNum = 3;
}
No comments:
Post a Comment