Back to Parent

// Define a pin that we'll place the fsr on
// Remember to add a 10K Ohm pull-down resistor too.
int fsrPin = A4;

// Create a variable to hold the light reading
int fsrReading = 0;

// Define a pin we'll place an LED on
int ledPin = D2;

// Create a variable to store the LED brightness.
int ledBrightness = 0;

void setup()
{

    // Create a cloud variable of type integer
    // called 'light' mapped to photoCellReading
    Particle.variable("force", &fsrReading, INT);

    // Set up the LED for output
    pinMode(ledPin, OUTPUT);
}

void loop()
{
    // Use analogRead to read the photo cell reading
    // This gives us a value from 0 to 4095
    fsrReading = analogRead(fsrPin);
    
    if (fsrReading > 1000 & fsrReading <= 2000) {
        ledBlink(1);
    } else if (fsrReading > 2000 & fsrReading <= 3000) {
        ledBlink(2);
    } else if (fsrReading > 3000) {
        ledBlink(3);
    } else {
        
    };

    // wait 1/10th of a second and then loop
    delay(100);
}

int ledBlink(int cnt)
{
    for(int i = 0; i < cnt; i++){
        // First... On
        digitalWrite(ledPin, HIGH);   // Turn ON the LED pins
        delay(500);  
        // Now... Off
        digitalWrite(ledPin, LOW);   // Turn OFF the LED pins
        delay(500);               // Wait for 500mS = .5 second
    }
    // Make sure the LEDs to be OFF
    digitalWrite(ledPin, LOW);
    return 1;
}
Click to Expand

Content Rating

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

0