Back to Parent

int photoCellPin = A0;
int photoCellReading = 0;

int ledPin = D2;
int ledBrightness = 0;

int switchPin = D3;
int buttonState = LOW;




void setup() {
    
    Particle.variable("light", &photoCellReading, INT);
    Particle.variable("button", buttonState);
    
    pinMode( switchPin , INPUT_PULLUP); // sets pin as input
    pinMode( ledPin , OUTPUT ); // sets pin as output

}

void loop() {
    
    photoCellReading = analogRead(photoCellPin);
    ledBrightness = map(photoCellReading, 1400, 3095, 0, 255);
    
    // buttonState = HIGH;
    buttonState = digitalRead(switchPin);
    
    if( buttonState == HIGH )
  {
    analogWrite(ledPin, ledBrightness);
    delay(100);
  }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