Back to Parent

int fsrPin = A0;
int led1Pin = D0;
int photoCellPin = A3;
int led2Pin = A1;
int fsrReading = 0;
int led1Brightness = 0;
int photoCellReading = 0;
int led2Brightness = 0;

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


}

void loop()
{
  // 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
  led1Brightness = map(fsrReading, 0, 3000, 0, 255);

  // fade the LED to the desired brightness, different levels will shine different times
   if (fsrReading < 500)
      {for (int i = 0; i < 1; i++)
       {
 // turn the pin on:
     analogWrite(led1Pin, led1Brightness);
     delay(500);
     analogWrite(led1Pin, 0);
     delay(500);
     } }


    else if ( fsrReading <1500)

     {for (int n = 0; n < 2; n++)
   {

      analogWrite(led1Pin, led1Brightness);
      delay(500);
      analogWrite(led1Pin, 0);
      delay(500);
      }}

   else
     {for (int c = 0; c < 3; c++)
         {

   analogWrite(led1Pin, led1Brightness);
   delay(500);
   analogWrite(led1Pin, 0);
   delay(500);
   } }

  // 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
  photoCellReading = analogRead(photoCellPin);

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

  // fade the LED to the desired brightness
  analogWrite(led2Pin, led2Brightness);

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