Sunday, October 11, 2015

10/11 Mini Project 1, Documentation, Jen Herrera

Mini Project 1: City Night
For this project, I set out to become familiar with the Arduino Lilypad, conductive thread, and sewing circuits. At the same time, I explored the idea of the city at night; It radiates with it's own light but because of the sheer amount of light pollution, blocks out the stars. In City Night, the night stars (twinkling LEDs sewn into the embroidery) only appear when the lights are turned off. A light sensor takes a base reading of the light in a room, and then only illuminates the stars if it gets darker.

Documentation Video:


 Code:
(below break)

 
/*
Built off of the Fade example sketch.
 */

int led1 = 11;
int led3 = 10;
int led2 = 9;
int brightness = 0;
int brightness2 = 0;// how bright the LED is
int fadeAmount = 5;
int fadeAmount2 = 7;// how many points to fade the LED by
int LDR = A5; //Added light sensor
int base;
int threshold = 30;
// the setup routine runs once when you press reset:
void setup() {
  // declare output/inputs:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(LDR, INPUT);
  base = analogRead(LDR);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pins:
 int v = analogRead(LDR); //if it's less light than base reading + threshold
   if ((base - v) > threshold) {
    analogWrite(led1, brightness);
    analogWrite(led2, brightness2);
    analogWrite(led3, brightness);  
} else { //If the same amt of light or brighter, lights are off
     analogWrite(led1, LOW);
     analogWrite(led2, LOW);
     analogWrite(led3, LOW);

   }
  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;
  brightness2 = brightness2 + fadeAmount2;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }
    if (brightness2 == 0 || brightness2 == 255) {
    fadeAmount2 = -fadeAmount2 ;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

No comments:

Post a Comment