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.

Monday, June 6, 2016

9. Holly and Ying's Prototyping Update 2

I incorporated previous code for a single LED bulb into a standard example code of DotStar LED strip. The LED strip at this stage would start to flow when the sensor detects something, and would stop flowing when there is nothing.
However, we want to change the brightness and colors of the LED strip, but this example code is the only DotStar code I could find online. This example is very basic, and it does not cover functions like setting brightness or specifying color, so I needed to do more research about those.



For sensor
 int led=12;
void setup() {
 Serial.begin(9600);
 pinMode(led,OUTPUT);
}


void loop() {
 int sensorValue=analogRead(A0);
 Serial.println(sensorValue);
 Serial.print("current time is ");
 Serial.println(millis()/1000);


 if(sensorValue<=130){
   Serial.print('N');
   Serial.print("no one here ");


 }else{
   Serial.print('Y');
   Serial.print("person here ");
   delay(100);


}
}


For Arduino with LED strip
#include <Adafruit_DotStar.h>
#include <SPI.h>      
#define NUMPIXELS 30
int incomingByte;  
int sensorValue;


#define DATAPIN    11
#define CLOCKPIN   13
Adafruit_DotStar strip = Adafruit_DotStar(
 30, 11, 13, DOTSTAR_BRG);


void setup() {


#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
 clock_prescale_set(clock_div_1);
#endif
 Serial.begin(9600);
 strip.begin();
 strip.show();  
}


int      head  = 0, tail = -10;
uint32_t color = 0xFF0000;      


void loop() {


if (Serial.available() > 0) {
   incomingByte = Serial.read();
   sensorValue=Serial.read();
   Serial.println(sensorValue);
   int value=map (sensorValue, -1, 80,0,255);
   Serial.println(value);
   if(incomingByte == 'Y'){
      strip.setBrightness(value);
      strip.setPixelColor(head, color);
      strip.setPixelColor(tail, 0);    
      strip.show();                    
      delay(100);                       


    if(++head >= NUMPIXELS) {         
       head = 0;                      
      if((color >>= 8) == 0)         
        color = 0xFF0000;             
     }
    if(++tail >= NUMPIXELS) tail = 0;


   }
   
   if(incomingByte == 'N'){
   strip.setBrightness(0);
   strip.show();                     
   delay(100);
   }
   
}
 

}

No comments:

Post a Comment