Back to Parent

int ledPin = D0;
int ledBrightness = 0;

int frsPin = A0;
int frsReading = 0;

int photoCellPin = A1;
int photoCellReading = 0;

int drink = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  Spark.variable("force", &frsReading, INT);
  Spark.variable("light", &photoCellReading, INT);
  Spark.variable("drink", &drink, INT);
}

void loop() {
  // Read from the frsPin, and use the reading to control brightness of the LED
  frsReading = analogRead(frsPin);
  ledBrightness = map(frsReading, 0, 4095, 0, 255);
  analogWrite(ledPin, ledBrightness);
  // Read from the photoCellReading
  photoCellReading = analogRead(photoCellPin);
  delay(100);
  // frsReading > 1000 means you have enough water; photoCellReading > 1000 means it's in the daytime
  if (frsReading > 1000 && photoCellReading > 1000) {
    drink = 1;
  } else {
    drink = 0;
  }
}
Click to Expand

Content Rating

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

0