For my ambient lighting project, I created a slowly illuminating alarm clock. The purpose of this isn't to wake up the user, but rather to get them out of the house within a certain amount of time after waking up, which always seems to be a problem in the mornings.
The housing was constructed of lasercut acrylic triangles, which I backpainted with opaque paint so that the light could only come through the cut-out letters. The LEDs were mounted on the same level as the letters, and some very low-tech tissues were used as a diffuse layer between the LEDs and the letters. The whole thing was covered in paper so that the letters only show up when they glow through.
A short video demonstrating it is here:
CODE
//Caitlin Morris
//Ambient Lighting Project//Rev 1.0
// initialize the two LEDs and the photoresistor (called inPin)
int ledPin = 9;
int ledPin2 = 8;
int inPin = 1;
// inputThreshold is the value at which light is clearly different from dark; can be changed based on room conditions
int inputThreshold = 100;
// determine whether or not there has been a change in state with a boolean
boolean wasBright = false;
// baseTime is the counter that starts when brightness is read
unsigned long baseTime;
// slowFadeTime is the amount of time for slow fade up
unsigned long slowFadeTime = 30 * 1000;
// pulseTime is the amount of time for the quick end pulse
int pulseTime = 5 * 1000;
// pulseSpeed is the modulus control for how quickly the LED pulses
int pulseSpeed = 100;
// This is the analog-write brightness of the lights
int maxLedBrightness = 128;
// declare your lights and sensor as input / output
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(inPin, INPUT);
digitalWrite(inPin, HIGH);
}
void loop(){
// starts a counter for time since the board is turned on
unsigned long absoluteTime = millis();
//if the value of the sensory is greater than the bright threshold, the light turns on
boolean isBright = analogRead(inPin) > inputThreshold;
// if it was dark and becomes bright, the counter records the time
if(isBright && !wasBright){
baseTime = absoluteTime;
}
// reset to current state
wasBright = isBright;
// this value takes the different between the start time of running and the start time of being bright
unsigned long relativeTime = absoluteTime - baseTime;
if(isBright){
// if it's within the designated slow fade time, slowly fade up the LEDs to full value over that time
if(relativeTime < slowFadeTime){
// remap the maximum time to the brightness of the LEDs
int fadeVal = map(relativeTime, 0, slowFadeTime, 0, maxLedBrightness);
ledSet(fadeVal);
// if it's after the slow fade time but still within the pulse time, pulse the LEDs
} else if(relativeTime < slowFadeTime + pulseTime) {
int fadeVal = map((relativeTime - slowFadeTime) % pulseSpeed, 0, pulseSpeed, 0, maxLedBrightness);
ledSet(fadeVal);
//if it's after both time periods, turn off the LEDs
} else {
ledSet(0);
}
// if it's dark, keep the LEDs off
} else {
ledSet(0);
}
}
// this is the function that turns on the LEDs according to the int fadeVal, declared above
void ledSet(int fadeVal) {
analogWrite(ledPin, fadeVal);
analogWrite(ledPin2, fadeVal);
}
Comments