Capacitor

Capacitor

Capacitor c’est une lampe qui emmagasine la lumière pour la redonner sur une durée plus longue.

Flore Gervais / Antoine Pintout

Circuit

Capaciter_bb

Principe

Quand le capteur détecte une augmentation de luminosité la carte Arduino allume la LED. De plus la carte compte la durée de l’augmentation et maintient la LED allumée sur une période dix fois plus longue.

Programme commenté

// CONFIG

#define LED 11		// LED pin (pwm)
#define LDR A0		// LDR sensor pin (analog)
#define SCANTIME 2000   // Scan ambiant luminosity during SCANTIME ms
#define CHARGE 80	// Difference to trigger "charging"
#define FACTOR 10 	// Time factor (time on = FACTOR times illuminated)

// VARIABLES

int envBrightness = 0;  // stores ambiant luminosity
int timeLeft = 0;	// stores time on left
int ledBrightness = 0;  // stores current LED brightness

void setup()  {

	// I/O setup
	pinMode(LED, OUTPUT);
	pinMode(LDR, INPUT);
	Serial.begin(9600);

	// Init var
	envBrightness = analogRead(LDR);	// Read the first value

	// Scan ambiant luminosity
	while(millis() < SCANTIME){		// then gather values for 5s
		envBrightness += analogRead(LDR);// and add it up to find a mean value
		envBrightness /= 2;
	}

	Serial.println(envBrightness);		// Output the mean value
} 

void loop()  {

	// Read luminosity and increment if 
	if(analogRead(LDR)-envBrightness > CHARGE){
		// Add time to the counter if LDR illuminated
		timeLeft += FACTOR * 1;		
		Serial.print("CHARGING\t");	// Output the counter value
		Serial.println(timeLeft);
	}

	// DIM
	if(timeLeft > 0){ // If there is time in the counter
		// increment the led brightness
		ledBrightness = min(255, ledBrightness + 3);
	}else{
		ledBrightness = max(0, ledBrightness - 1);  // If not : decrement it.

	}	

	// Apply results to LEDs
	analogWrite(LED, ledBrightness);

	// Decrement time left an wait 10ms
	timeLeft = max(0, timeLeft - 1);
	delay(10);
}

Demo

Capacitor from Studio Objet Augmente on Vimeo.

Capacitor