// Define a pin that we'll place the photo cell on
// Remember to add a 10K Ohm pull-down resistor too.
int photoCellPin = A0;
int tempSensePin = A1;
// Create a variable to hold the light reading
int photoCellReading = 0;
int tempSenseReading = 0;
// Define a pin we'll place an LED on
int ledPin = D2;
// Create a variable to store the LED brightness.
int ledBrightness = 0;
int tempConvert = 0;
void setup()
{
// Set up the LED for output
pinMode(ledPin, OUTPUT);
// Create a cloud variable of type integer
// called 'light' mapped to photoCellReading
Particle.variable("light", &photoCellReading, INT);
Particle.variable("temp", &tempSenseReading, INT);
Particle.variable("tempConvert", &tempConvert, INT);
}
void loop()
{
// Use analogRead to read the photo cell reading
// This gives us a value from 0 to 4095
photoCellReading = analogRead(photoCellPin);
tempSenseReading = analogRead(tempSensePin);
tempConvert = ((((tempSenseReading * 0.8) - 500) / 10) * 1.8) + 32;
if (tempConvert > 75)
{
// Map this value into the PWM range (0-255)
// and store as the led brightness
// fade the LED to the desired brightness
ledBrightness = map(photoCellReading, 1000, 4095, 0, 255);
}
else
{
ledBrightness = 0;
}
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. .