Back to Parent

int fsrPin = A0;
int fsrReading = 0;
int ledPin = D2;
int ledBrightness = 0;
int switchPin = D5;
int pinState = 0;

void setup() {
    pinMode(switchPin , INPUT_PULLUP);
    pinMode(ledPin, OUTPUT);
    Particle.variable("force", &fsrReading, INT);
    Particle.variable("led", &ledBrightness, INT);
}

void loop() {
    pinState = digitalRead( switchPin );
    
    if(pinState==LOW) {
        fsrReading = analogRead(fsrPin);
        ledBrightness = map(fsrReading, 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