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, May 19, 2015

No Phones At The Table – Testing NeoPixel – Rishi Agarwal and Annie Pyle


We got our NeoPixel recently and we wanted to test it out. We hooked it up to the Arduino and made some demo code to teach ourselves the API. This animation is similar to what we might have in the final product. The code is below. If you want to see a formatted version, check here: http://pastebin.com/6Qxcq7QR



//import good stuff to make the neopixel work
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>

//define pin for neopixel
#define PIN 6

//initialize the neopixel object (number of LEDs, pin number, color mode)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.setBrightness(3);
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  int line = 11;
  lineLoop(line);
  lineStatic(line);
  lineResize(line);
  lineStatic(line);
}

//creates a line that moves around the ring
void lineLoop(int length) {
  for (int i = 0; i < 24; i++) {
    for (int j = 0; j < length; j++) {
      int light = i + j;
      if (light > 23) {
        light -= 24;
      }
      strip.setPixelColor(light, strip.Color(255, 0, 0));
    }
    strip.show();
    delay(50);
    for (int k = 0; k < 24; k++) {
      strip.setPixelColor(k, 0);
    }
    strip.show();
  }
}

//creates a line in place
void lineStatic(int length) {
  for (int i = 0; i < length; i++) {
    strip.setPixelColor(i, strip.Color(255, 0, 0));
  }
  strip.show();
  delay(500);
}

//shrinks the line and expands it to its previous size
void lineResize(int length) {
  for (int j = 0; j < 3; j++) {
    //shrinks
    for (int i = 0; i < ((length-1)/2); i++) {
      strip.setPixelColor(i, 0);
      strip.setPixelColor(length-1-i, 0);
      strip.show();
      delay(75);
    }
 
    //expands
    for (int i = ((length-1)/2) - 1; i >= 0; i--) {
      strip.setPixelColor(i, strip.Color(255, 0, 0));
      strip.setPixelColor(length-1-i, strip.Color(255, 0, 0));

      strip.show();
      delay(16);
    }
  }
}

No comments:

Post a Comment