int ledPin = D2;
int sensorPin = A0;
int lightRead = 0;
int ledBright = 0;
void setup() {
pinMode(ledPin, OUTPUT);
Particle.variable("light", lightRead);
Particle.variable("led", ledBright);
}
void loop() {
lightRead = analogRead(sensorPin); // read the lightResister
ledBright = 255 - map(lightRead, 0, 4095, 0, 255);
analogWrite(ledPin, ledBright); // if the light is brighter, the LED light is stonger
}
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. .