Back to Parent

int photoCellPin = A0;
int photoCellReading = 0;
int ledPin = D2;
int ledBrightness = 0;
int buttonPin = D4;

void setup() {
    pinMode(ledPin, OUTPUT);
    Particle.variable("light", &ledBrightness, INT);
    pinMode( buttonPin , INPUT_PULLUP);
    
}

void loop() {
    int buttonState = digitalRead( buttonPin );

     if( buttonState == LOW ){
     photoCellReading = analogRead(photoCellPin);
     ledBrightness = map(photoCellReading, 3000, 4095, 0, 255);
     printf("%d", ledBrightness);
     analogWrite(ledPin, ledBrightness);
     delay(100);
     }
     
    else{
      digitalWrite( ledPin, LOW);
    }
    
    Particle.publish("light");

}
Click to Expand

Content Rating

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

0