Back to Parent

int photoCellPin = A0;
int photoCellReading = 0;
int ledPin = D0;
int fsrPin=A1;
int fsrReading=0;
int tempPin=A2;
double temperature=0.0;
double temperatureF=0.0;
int ledPin1=D1;
int led1Brightness=0;


void setup(){
  pinMode(ledPin, OUTPUT);
  Spark.variable("light", &photoCellReading, INT);
  Spark.variable("force",&fsrReading,INT);
  digitalWrite(ledPin,LOW);
  digitalWrite(ledPin1,LOW);
  Spark.variable("temperature",&temperature,DOUBLE);
  Spark.variable("temperatureF",&temperatureF,DOUBLE);
  pinMode(ledPin1,OUTPUT);
  pinMode(tempPin,INPUT);
}

void loop() {

  fsrReading=analogRead(fsrPin);
  photoCellReading = analogRead(photoCellPin);
  //ledBrightness = map(photoCellReading, 0,4095,0,255);
  //digitalWrite(ledPin1,led1Brightness);
  if(photoCellReading<500&fsrReading>100)
  {
    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin1,led1Brightness);
}

else
{
  digitalWrite(ledPin,LOW);
  int reading=analogRead(tempPin);
  double voltage = (reading*3.3)/4095.0;
  temperature=(voltage-0.5)*100;
  temperatureF=((temperature*9.0)/5.0)+32.0;
  led1Brightness=map(temperature,0,50,0,255);
  analogWrite(ledPin1,led1Brightness);

}
  }
Click to Expand

Content Rating

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

0