Back to Parent

#include <NewPing.h>

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
int distance;
int heart_rate;
int attention;
long timer = 0;
long run_time = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
    distance = sonar.ping_cm();
    heart_rate = random(70,72);
    if (distance > 8) {
      if (millis() - timer >= 1500) {
        heart_rate = random(86, 88);
        Serial.print(heart_rate);
        Serial.print(" ");
        if ((millis() - run_time > 2000) && (millis() - run_time <= 5000)) {
          attention = random(80,85);
          Serial.println(attention);
        }
          else if ((millis() - run_time <= 6500) && (millis() - run_time > 5000)){
            attention = random(75,80);
            Serial.println(attention);
          }
          else {
          attention = random(66, 70);
          Serial.println(attention);
          }
  }
  if (millis() - timer >= 1530) {
      timer = millis();
      heart_rate = random(60, 62);
      Serial.print(heart_rate);
      Serial.print(" ");
    }
    else {
    Serial.print(heart_rate);
    Serial.print(" ");
    }
  
  if (millis() - run_time <= 2000) {
  attention = random(66, 70);
  Serial.println(attention);
  }
  else if (millis() - run_time <= 5000) {
    attention = random(80,85);
    Serial.println(attention);
  }
  else if (millis() - run_time <= 6500) {
    attention = random(75,80);
    Serial.println(attention);
  }
    else if (millis() - run_time <=7500) {
    attention = random(70,75);
    Serial.println(attention);
  }
  else {
    attention = random(66,70);
    Serial.println(attention);
  }
  }
  else{
    run_time = millis();
    Serial.print(0);
    Serial.print(" ");
    Serial.println(0);
  }
}
Click to Expand

Content Rating

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

0