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.
Showing posts with label Fibonacci Sequence. Show all posts
Showing posts with label Fibonacci Sequence. Show all posts

Friday, April 25, 2014

Jered and Ciera | Arduino | Fibonacci Sequence Blinking

Writing an Arduino sketch to blink an LED according to the Fibonacci Sequence is fairly straightforward. The two main variables you need to keep track of are the last two numbers in the sequence. Without them, it is impossible to keep track of where you are as you step through the sequence!

The second important part of code is a loop that blinks the light repeatedly, however many times you need it to according to where in the sequence you are.

Source code posted below:

/*
Fibonacci Number Sequence counter
by Jered Danielson and Ciera Johl, 25 April 2014

This sketch blinks the LED on "ledPin" according to the Fibonacci Sequence.

The Fibonacci Sequence is defined as Fn = Fn-1 + Fn-2, such as
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89... etc.
*/

int ledPin = 13; // LED pin for output
int numberOne = 0; // Fn-2
int numberTwo = 1; // Fn-1
int delayTime = 400; // Delay time in milliseconds between blinks

void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
}

void loop() {
  int currentNumber = numberOne + numberTwo; // next number equals the sum of the last two
  // Blink the LED "currentNumber" number of times
  for(int i = currentNumber; i > 0; i--) {
     digitalWrite(ledPin, HIGH);
     delay(delayTime/2);
     digitalWrite(ledPin, LOW);
     delay(delayTime/2);
  }
  
  // Update the two stored numbers of the sequence
  numberOne = numberTwo;
  numberTwo = currentNumber;
  
  delay(delayTime*3);
}

Thursday, April 24, 2014

Arduino Fibonacci Sequence LED | Albert Lui + Anjelica Harlow

Hi. This is Albert and Angelica. Here is the code for making an LED blink the Fibonacci Sequence. No fancy code or mathematical equations for this one. It basically treats the first Fibonacci number as if it were the beginning of a fencepost problem and solves it as a single unique case. It's true that performing the if/else check every single time the void loop is run seems to be redundant, but in reality, a single conditional statement test should have a negligible effect on the time complexity of the entire program. Variables are used to remember what values are in the n-1 and n-2 spots of the sequence and updated after blinking the LED.

/*
  A simple program that blinks an LED a number of times in accordance with the Fibonacci Sequence (1, 1, 2, 3, 5, 8, 13, 21 . . .)
  There are 3 second delays between each Fibonacci number.
 */

int led = 13;
int nMinus1 = 0; // keeps track of the previous number
int nMinus2 = 0; // keeps track of the number before the previous
int blinks = 0; // number of times to blink the LED


void setup() {              
  pinMode(led, OUTPUT);  
}

void loop() {
  // Takes care of the first case like a classic fencepost problem
  if (nMinus1 == 0) {
    digitalWrite(led, HIGH);
    delay(200);            
    digitalWrite(led, LOW);
    delay(200);
    nMinus1 = 1;
  } else {  
    blinks = nMinus1 + nMinus2;
    for (int x = 0; x < blinks; x++) {
      digitalWrite(led, HIGH);
      delay(300);            
      digitalWrite(led, LOW);  
      delay(300);            
    }
  nMinus2 = nMinus1;
  nMinus1 = blinks;
  }
  delay(3000);
}

Tuesday, April 22, 2014

Ichikawa & Lim - Fibonacci

Dominic Challenged the class to make an Arduino blink a light to the Fibonacci sequence. Catherine and I quickly write up a script to make this work. Seems pretty straight forward, and seems to work well.

Excited to see what else this Arduino can do!

Scott & Catherine

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
int aNum;
int bNum;
int cNum;


// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT); 
  aNum = 0;  
  bNum = 1;  
  cNum = 0;  
  Serial.begin(9600); 
}

// the loop routine runs over and over again forever:
void loop() {
  cNum = aNum + bNum;
  Serial.println(cNum);
  for(int i = 0; i < cNum; i++){
      digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(30);               // wait for a second
      digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
      delay(300);   
  }
  //Serial.println(cNum);
  delay(1000);  
  
  aNum = bNum;
  bNum = cNum;
}