Back to Parent

const int ldrpin = A4;
int lightlevel = 0;
int ledPin = D0;
int threshold = 150; // threshold at which we consider the room light or dark

void setup(){
   pinMode(ldrpin, INPUT);
   pinMode(ledPin, OUTPUT);
   Spark.variable("lightlevel", &lightlevel, INT);
}

void loop(){
   lightlevel = analogRead(ldrpin);
   if (lightlevel > threshold) {
     digitalWrite(ledPin, HIGH);
   }
   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