As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.

Tuesday, April 29, 2014

Chris & Skyler make Fibonacci blinking magic

The other day we figured out a code to blink the Fibonacci sequence ( 1, 1, 2, 5, 8, 13, 21, 34... ) Following the series of blinking experiments from creating this sequence was relatively simple. Main components were creating int variables that guided the codes changes of state. Check out how we did it below! 


/*
Fibonacci
 */
 
//The power out of digital 13
int led = 13;
int prev = 0;
int cur = 1;

void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  for(int i = 0; i < cur; i++){
    flashOnce();
  }
  delay(800);
  int temp = cur; //sset a holder for the current number
  cur = cur + prev; //current number + previous number
  prev = temp; //previous is now current.
}

//method for flashing once
void flashOnce() {
    digitalWrite(led, HIGH);
    delay(200);
    digitalWrite(led, LOW);
    delay(200);
}

No comments:

Post a Comment