Back to Parent

//#1 and #2

int snsr_light = A0;
int light_reading = 0;
int led = D2;
int led_bright = 0;

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

Particle.variable("light sensor",&light_reading,INT);

}

void loop() {

light_reading = analogRead(snsr_light);
analogWrite(led,led_bright);

//#1 Brighter LED in brighter light
// led_bright = map(light_reading, 1500,4095,0,255);

//#2 Brighter LED in lower light
led_bright = map(light_reading, 1000,3000,255,0);

delay(100);


}

//#3
int snsr_light = A0;
int light_reading = 0;
int led = D2;
int led_bright = 0;

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

Particle.variable("light sensor",&light_reading,INT);

}

void loop() {

if (analogRead(snsr_light) < 1200)

    digitalWrite(led,HIGH);
    
else

    digitalWrite(led,LOW);

}
Click to Expand

Content Rating

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

0