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.

Sunday, June 15, 2014

Coding by Freistadt/Hart



#include <Adafruit_NeoPixel.h>
#include <SharpIR.h>
#include <DistanceGP2Y0A21YK.h>                       // LINEAR SENSOR LIBRARY ADD

DistanceGP2Y0A21YK Dist;                              // LINEAR SENSOR LIBRARY ADD
int distance;                                         // LINEAR SENSOR LIBRARY ADD

#define PIN 6
#define ir A0
#define model 1080

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

SharpIR sharp(ir, 25, 93, model);

/*
ir: the pin where your sensor is attached
25: the number of readings the library will make before calculating a mean distance
93: the difference between two consecutive measurements to be taken as valid
model: an int that determines your sensor:  1080 for GP2Y0A21Y
*/

void setup()

{
  Serial.begin(9600);
  pinMode (ir, INPUT);
 
  Dist.begin(A0);                                          // LINEAR SENSOR LIBRARY ADD
 
  strip.begin();
  strip.show();                                            // Initialize all pixels to 'off'
}


void loop()

{
  int dis=sharp.distance();                                // this returns the distance to the object you're measuring
 
  distance = Dist.getDistanceCentimeter();                 // LINEAR SENSOR LIBRARY ADD
  Serial.print("Distance in centimers: ");                 // LINEAR SENSOR LIBRARY ADD
  Serial.print(distance);                                  // LINEAR SENSOR LIBRARY ADD
 
  Serial.print("  // Mean distance: ");                    // returns it to the serial monitor
  Serial.println(dis);                                     // print distance
   
  dis = map(dis, 0, 130, 0, 230);                          // convert range to color value
 
  if(dis >= 0 && dis <= 220) {                             // if distance is in range
   
    colorWipe(strip.Color(255-dis, 255-dis, 255-dis));     // White lights based off proximity sensivity
     
  } else {

    colorWipe(strip.Color(0, 0, 0));                       // Nothing
   
  }
}

void colorWipe(uint32_t c) {                               // function to control NeoPixels
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
  }
      strip.show();
}

No comments:

Post a Comment