Back to Parent

// Define fsr pin
int fsrPin = A0;

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

// Define fsrLED
int ledPin1 = D0;

// LED brightness.
int ledBrightness1 = 0;

// Define photoCell
int photoCellPin = A1;

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

// Define photoLED
int ledPin2 = D1;

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

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

}

void loop()
{

  if ( fsrReading > 0 ){
    ledBrightness2 = map(photoCellReading, 0, 4095,455, 0);
    photoCellReading = analogRead(photoCellPin);

  }


  // fade the LED to the desired brightness
  analogWrite(ledPin2, ledBrightness2);

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

  // 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