Back to Parent

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 = map(lightRead, 0, 4095, 0, 255);
    analogWrite(ledPin, ledBright); // if there is lots of light, the LED is dim
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0