Back to Parent

int fsrPin = A0;
int fsrReading = 0;
int ledPinB = D2; 
int ledPinG = D3;
int ledPinY = D4;
int b = 0;
int g = 0;
int y = 0;

void setup() {
    pinMode(ledPinB, OUTPUT);
    pinMode(ledPinG, OUTPUT);
    pinMode(ledPinY, OUTPUT);
}

void loop() {
    fsrReading = analogRead(fsrPin);

    if(fsrReading < 100){                                   //This means the cup is not on the coaster
        digitalWrite(ledPinB, LOW);                         //Turn off lights from other states of
        digitalWrite(ledPinG, LOW);                         //the coaster
        b = 0;
        g = 0;
        y++;                                                //Timer setup to delay the reminder to user
        if(y>20){
            digitalWrite(ledPinY, HIGH);                    //Reminder to place cup on coaster
        }
    }
    
    else if(100 < fsrReading && fsrReading < 2000){         //This means the cup is on the coaster but is empty
        digitalWrite(ledPinY, LOW);
        digitalWrite(ledPinG, LOW);
        g = 0;
        y = 0;
        b++;
        if (b>50){                                          //Timer to delay reminder to user
            digitalWrite(ledPinB, HIGH);                    //Reminder to fill cup and drink water
        }
    }
    
    else if(fsrReading > 2000){                             //This means the cup is on the caster and filled
        digitalWrite(ledPinY, LOW);
        digitalWrite(ledPinB, LOW);        
        b = 0;
        y = 0;
        g++;
        if (g>50){
            digitalWrite(ledPinG, HIGH);
        }
    }

    delay(100);
    Particle.variable("force", &fsrReading, INT);           //Sending the fsr reading to console to calibrate
                                                            //weight of the empty and filled cup
}
Click to Expand

Content Rating

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

0