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 = A0;

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

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

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

void setup()
{
  // Set up the LED for output
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  
    // Create a cloud variable of type integer
  // called 'light' mapped to photoCellReading
  Particle.variable("force", &fsrReading, INT);
}

void loop()
{
  // Use analogRead to read the photo cell reading
  // This gives us a value from 0 to 4095
  fsrReading = analogRead(fsrPin);
  
  if (fsrReading <= 1365){
      ledBrightness = map(fsrReading, 0, 1365, 0, 255);
      analogWrite(ledPin, ledBrightness);
      analogWrite(ledPin2, 0);
      analogWrite(ledPin3, 0);
  }else if(fsrReading > 1365 && fsrReading <= 2730) {
      ledBrightness = map(fsrReading, 1365, 2730, 0, 255);
      analogWrite(ledPin2, ledBrightness);
      analogWrite(ledPin, 255);
      analogWrite(ledPin3, 0);
  }else{
      ledBrightness = map(fsrReading, 2730, 4095, 0, 255);
      analogWrite(ledPin, 255);
      analogWrite(ledPin2, 255);
      analogWrite(ledPin3, 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