int photoCellPin =A0;
int photoCellReading=0;
int ledPin=D2;
int ledBrightness=0;
void setup() {
pinMode(ledPin, OUTPUT);
Particle.variable("light",&photoCellReading, INT);
}
void loop() {
//analogRead reads the photocell, and gives a value from 0 to 4095
photoCellReading =analogRead (photoCellPin);
//We want to map this value into the PWM range of 0-255
ledBrightness =map(photoCellReading, 3000,4095,0,255);
//fade the LED to the desired brightness, sets the value
analogWrite(ledPin, ledBrightness);
//waits and then loops
delay(100);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .