Description
A firefly that lights up when you cup your hands around him.
Components
- Sculpy body
- Tiny green LED
- 220Ohm resistor
- 10KOhm resistor
- Photo resistor
Arduino Code
int sensorPin = 0; // select the input pin for the sensor
int ledPin = 11; // select the output pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
}
void loop() {
val = analogRead(sensorPin);
int val1 = 230-val/4; //offset it by a little... full brightness is rare
int pulse = 0;
for(pulse=0; pulse<val1; pulse++){
analogWrite(ledPin, pulse);
delay(10);
}
pulse = val1;
for(pulse=val1; pulse>0; pulse--){
analogWrite(ledPin, pulse);
delay(10);
}
//Serial.println(val1);
delay(50);
}
Firefly