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.

Wednesday, June 10, 2015

Neopixel Fun

For the timer that controls the length of time that the phone is held down for we wanted to include a visual indicator to show the increasing or decreasing time. After looking at products on adafruit we decided that a neopixel ring combined with a twist knob would be the best combination to show this. 


Hooking up the neopixels and supporting library was quick although learning some of the commands and methods for controlling the individual pixels was more difficult than anticipated. Specifically turning the pixels back off.

Wiring setup for testing. Potentiometer hooked up to the neopixel ring for control.

The following is the code that created the lighting pattern that we settled on. The code makes the lights go from green to red following the rotation of the twist knob.

#include <Adafruit_NeoPixel.h>
#include <avr/power.h>

#define PIN            6

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      24

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 5; // delay for half a second

void setup() {
  
Serial.begin(9600);
  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {

  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
int sensorValue = analogRead(A0);
 int green = 0;
 int red = 0;
 int pixel = 0;
 pixel = map (sensorValue, 0, 1023, 0, 50);
 red = map (sensorValue, 0, 1023, 0, 50);
 green = map (sensorValue, 0, 1023, 50, 0);
 int something=map(sensorValue,0,1023,0,24);

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.clear();
    for (int i=0; i<something; i++){
    pixels.setPixelColor(i , pixels.Color(red, green , 0)); // Moderately bright green color.
    
    pixels.show(); // This sends the updated pixel color to the hardware.
    }
    
    

  
}

No comments:

Post a Comment