Back to Parent

// Define a pin that we'll place the photo cell on
int photoCellPin = A1;

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

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

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

// Define a pin we'll place FSR on
int fsrPin = A0;

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

//
void setup(){

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

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

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

void loop() {
  // Use analogRead to read the photo cell reading
  // This gives us a value from 0 to 4095
  photoCellReading = analogRead(photoCellPin);
  // Use analogRead to read the fsr reading
  // This gives us a value from 0 to 4095
  fsrReading = analogRead(fsrPin);
  // light range over 2000 will trigger the light to be on
  // value based on test reads, 0 to 4095
  // light simulates motor for blinds
  // when photoCell reading is bright, blinds are traveling down
  if (photoCellReading > 2000)
  {
  // LED on because light is coming in
    digitalWrite(ledPin, HIGH);
}
  // otherwise, LED will be off because there is not enough light
  // blinds can be open
  // motor in blinds not on
else {
  digitalWrite(ledPin, LOW);
}
  // fsr sensor simulates blinds hitting a certain point, being closed
  // if the light coming in the window is above threshold and fsr sensor
  // is being pressed (blinds closed) then the blind motor will stop
  // values based on test reads, 0 to 4095
 if (photoCellReading > 2000 && fsrReading > 3000)
 {
  // blind motor will stop, light off
  digitalWrite(ledPin, LOW);
}

}
Click to Expand

Content Rating

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

0