// Ex 1.1
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);
// Map this value into the inverted PWM range
ledBrightness = map(photoCellReading, 0, 4095, 255, 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!
You must login before you can post a comment. .