Back to Parent

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

// Create a variable to hold the Flex reading
int flexReading = 0;
int flexReading1 = 0;

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

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


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

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

// Define a pin we'll place an LED on
int ledPin1 = D5;

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



void setup() {


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

  // Create a cloud variable of type integer
  // called 'light' mapped to photoCellReading
  Particle.variable("force", &flexReading, INT);
  Particle.variable("bent", state);
  
  
  
    // Set up the LED for output
  pinMode(ledPin1, OUTPUT);

}





void loop() {



  // Use analogRead to read from the sensor
  // This gives us a value from 0 to 4095
  flexReading = analogRead(flexPin);
  flexReading1 = 4095 - flexReading;

  // Map this value into the PWM range (0-255)
  // and store as the led brightness
  ledBrightness = map(flexReading1, 3000, 4095, 0, 255);

  // fade the LED to the desired brightness
  analogWrite(ledPin, ledBrightness);


  // wait 1/10th of a second and then loop
  delay(100);
  
  //if flexReading1 >3000, then then particle publish ..... am i doing it right?
  

    if (flexReading1 > 3700)
    {
        state = 1;
    }
    else 
    {
        state = 0;
    }
    
    
      // Use analogRead to read the photo cell reading
  // This gives us a value from 0 to 4095
  fsrReading = analogRead(fsrPin);

  // Map this value into the PWM range (0-255)
  // and store as the led brightness
  ledBrightness1 = map(fsrReading, 0, 4095, 0, 255);

  // fade the LED to the desired brightness
  analogWrite(ledPin1, ledBrightness1);

  // wait 1/10th of a second and then loop
  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