Back to Parent

int temp = A4;
int force = A0;
int tempG = D5;
int tempR = D4;
int forceG = D1;
int forceR = D0;
int forceReading = 0;
int tempReading = 0;
int thresh = 850;

void setup() {

pinMode(tempG, OUTPUT);
pinMode(tempR, OUTPUT);
pinMode(forceR, OUTPUT);
pinMode(forceG, OUTPUT);
  Spark.variable("Force", &forceReading, INT);
  Spark.variable("Temperature", &tempReading, INT);
}

void loop() {

forceReading = analogRead(force);
tempReading = analogRead(temp);

  if (forceReading >= 10 && forceReading < 1000) {
    digitalWrite(forceR, HIGH);
    digitalWrite(forceG, LOW);
  }

    else if (forceReading >=1000) {
    digitalWrite(forceR, LOW);
    digitalWrite(forceG, HIGH);
  }

      else if (forceReading <10) {
    digitalWrite(forceR, LOW);
    digitalWrite(forceG, LOW);
  }


      if (tempReading < thresh) {
    digitalWrite(tempG, HIGH);
    digitalWrite(tempR, LOW);
    }

    else if (tempReading >= thresh) {
    digitalWrite(tempG, LOW);
    digitalWrite(tempR, HIGH);
    }

    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