Back to Parent

int potPin = A5;
int potReading = 0;
int ledPin = D2;
int ledBrightness = 0;
int switchPin = D4;


void setup() {
    Particle.variable("pot", potReading);
    pinMode(ledPin, OUTPUT);
    pinMode(switchPin, INPUT_PULLUP);

}

void loop() {
    int buttonState = digitalRead(switchPin);
    
    if(buttonState == LOW) {
        digitalWrite(ledPin, HIGH);
        potReading = analogRead(potPin);
        ledBrightness = map(potReading, 0, 4095, 0, 255);
        analogWrite(ledPin, ledBrightness);
        delay(100);
    } 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