Back to Parent

int forcePin = A0;
int forceReading = 0;

int greenPin = D3;
int yellowPin = D4;
int orangePin = D5;
int redPin = D6;

int greenThresh = 100;
int yellowThresh = 800;
int orangeThresh = 1600;
int redThresh = 2400;
int offThresh = 3200;


void setup() {
    pinMode(greenPin, OUTPUT);
    pinMode(yellowPin, OUTPUT);
    pinMode(orangePin, OUTPUT);
    pinMode(redPin, OUTPUT);
    
    Particle.variable("Force Reading", forceReading);
}

void loop() {
    
    forceReading = analogRead(forcePin);
    
    if (forceReading >= greenThresh and forceReading < yellowThresh) {
        digitalWrite(greenPin, HIGH);
    }
    if (forceReading >= yellowThresh and forceReading < orangeThresh) {
        digitalWrite(yellowPin, HIGH);
    }
    if (forceReading >= orangeThresh and forceReading < redThresh) {
        digitalWrite(orangePin, HIGH);
    }
    if (forceReading >= redThresh and forceReading < offThresh) {
        digitalWrite(redPin, HIGH);
    }
    if (forceReading >= offThresh) {
        digitalWrite(greenPin, LOW);
        digitalWrite(yellowPin, LOW);
        digitalWrite(orangePin, LOW);
        digitalWrite(redPin, LOW);
    }
    delay(250);
}
Click to Expand

Content Rating

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

0