Back to Parent

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

void setup()
{
  pinMode(ledPin, OUTPUT);

  // Create a cloud variable of type integer called 'light' mapped to photoCellReading
  Particle.variable("light", &photoCellReading, INT);

}

void loop()
{
  // This gives us a value from 0 to 4095
  photoCellReading = analogRead(photoCellPin);
  
  if (photoCellReading < 2000) {
      ledBrightness = 255;
  }
  else {
      ledBrightness = 0;
  }

  // fade the LED to the desired brightness
  analogWrite(ledPin, ledBrightness);

  // wait 1/10th of a second and then loop
  delay(100);
}
Click to Expand

Content Rating

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

0