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 12, 2016

Arduino Exercises - Natalie and Logan

1) Alter the speed at which the light blinks
The code below increases the duration the light is on to two seconds and decreases the time it is off to one tenth of a second. The setup code is not included because it remains unchanged from the original blink code.

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(2000);              // wait for a two seconds
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(100);              // wait for one tenth of a second
}

2) Alternate between two separate lights
This code causes the first light to blink on then off and then signals the second light to do the same

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

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second

  digitalWrite(10, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(10, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

3) Increase the number of blinks by one with every pass
This code uses a simple for loop to execute the blink where the number of times to run the loop increases by one each time. There is a pause of three seconds between each count.

int count = 1;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  for(int i =0; i < count; i++) {
    digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);              // wait for a second
    digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
    delay(100);
  }
  count++;
    delay(3000);   // wait for three seconds
}

No comments:

Post a Comment