int led = D2;
int switch = D3;
int lightPin = A3;
int lightNum = 0;
int ledBrightness = 0;
void setup() {
pinMode(switchPin, INPUT_PULLUP);
pinMode(led, OUTPUT);
Particle.variable("light", lightNum);
}
void loop() {
int buttonState = digitalRead(switch);
if(buttonState == LOW){
digitalWrite(led, HIGH);
lightReading = analogRead(lightSensorPin);
ledBrightness = map(lightReading, 4095, 2000, 0, 255);
analogWrite(led, ledBrightness);
delay(500);
}
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!
You must login before you can post a comment. .