Back to Parent

int forcePin = A0;
int forceReading = 0;
int ledPin = D2;
int ledBrightness = 0;
int switchPin = D4;


void setup() {
    pinMode(ledPin, OUTPUT);
    pinMode(switchPin, INPUT_PULLUP);
    Particle.variable("Force Reading", forceReading);
}

void loop() {
    
    int switchState = digitalRead(switchPin);
    
    if (switchState == LOW) {
        digitalWrite(ledPin, LOW);
    }else{
        forceReading = analogRead(forcePin);
        ledBrightness = map(forceReading,0,4095,0,255);
        analogWrite(ledPin, ledBrightness);
    }
    delay(100);
}
Click to Expand

Content Rating

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

0