Back to Parent

int ledPin1 = D2;
int ledPin2 = D0;
int buzzer = D3;
int buttonPin = D1;

bool isMediating = false;
long mediationStartTime = -1;


void setup()
{
  interrupts(); // added to make recognize DHT library
  pinMode( buttonPin , INPUT_PULLUP); // sets pin as input
  pinMode( ledPin1 , OUTPUT ); // sets pin as output
  pinMode( ledPin2 , OUTPUT );
  pinMode(buzzer, OUTPUT);
  digitalWrite( ledPin1, LOW);
  digitalWrite(ledPin2, LOW);

  //tone(buzzer, 1000, 500);

}

void loop()
{
// find out if the button is pushed or not by reading from it.
   int buttonState = digitalRead( buttonPin );

   // switch LED color to signify timer starting
  if( isMediating == false && buttonState == LOW )
  {
    // read temp of dht and display
    tempReading = analogRead(DHTPIN);
    // blink blue LED to signify starting timer
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin1, HIGH);
    delay(500);
    digitalWrite(ledPin1, LOW);
    delay(500);
    digitalWrite(ledPin1,HIGH);
    delay(500);
    digitalWrite(ledPin1,LOW);


    // start the mediation cycle...
    isMediating = true;
    // keep a track of when we started meditating
    mediationStartTime = millis();
  }else{
    // otherwise turn white led on during meditation session
    digitalWrite( ledPin2, HIGH);

  }

// signal buzzer and flash blue light to signify end of meditation session (10 minutes is up)
  if( isMediating == true and mediationStartTime + 600000 < millis() ) {
    tone(buzzer, 1000, 500);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin1, HIGH);
    delay(500);
    digitalWrite(ledPin1, LOW);
    delay(500);
    digitalWrite(ledPin1,HIGH);
    delay(500);
    digitalWrite(ledPin1,LOW);

    // update the start
    isMediating = false;
    mediationStartTime = -1;
  }
  // turn off both lights
  if ( isMediating == false ) {
    digitalWrite(ledPin1,LOW);
    digitalWrite(ledPin2, LOW);
  }
  // anything less than 10 minutes, white light is on
  else {
    digitalWrite(ledPin2, HIGH);
  }

	}
Click to Expand

Content Rating

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

0