Back to Parent

int ledPin = D2;
int sensorPin = A0;
int lightRead = 0;
int ledBright = 0;
int lightResist = 0;

void setup() {
    pinMode(ledPin, OUTPUT);
    Particle.variable("light", lightRead);
    Particle.variable("led", ledBright);
}

void loop() {
    lightRead = 4095 - analogRead(sensorPin); // read the light
    lightResist = analogRead(sensorPin);
    if(lightRead < 600){
        ledBright = map(lightResist, 0, 4095, 0, 255);
        analogWrite(ledPin, ledBright); 
    }else{
        digitalWrite(ledPin, LOW);
    }
}
Click to Expand

Content Rating

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

0