Thursday, May 1, 2014

Fibonacci (Charlotte + Kendall)



Fibonacci Sequence



int led = 13;
int previousNumber = 0;
int currentNumber = 1;

void setup() {              

  pinMode(led, OUTPUT);  
}

//
void loop() {
  for(int i = 0; i < currentNumber; i++){
    blinkOneTime();
  }
  delay(800);
  // current number
  int temporary = currentNumber;
  // combining
  currentNumber = currentNumber + previousNumber;
  //previousNumber set currentNumber.
  previousNumber = temporary;
}


//blink once
void blinkOneTime() {
    digitalWrite(led, HIGH);
    delay(200);
    digitalWrite(led, LOW);
    delay(200);
}

No comments:

Post a Comment