Back to Parent

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

int buttonPin = D3;
int buttonState;

int potPin = A0;
int potReading = 0;

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

}

void loop() {
    
    buttonState = digitalRead(buttonPin);
    
    potReading = analogRead(potPin);
    
    if(buttonState ==LOW){

        int ledBrightness = map(potReading, 0,4095, 0,255);
        analogWrite( ledPin, ledBrightness);
    } 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