Trouble getting 4 HC-SR504 sensors to communicate to a TFT 2.8 CAP SCREEN

Hello,

I’m doing a project for college and I’m having trouble getting things to work properly.

I’ve gotten to the point where I can see the serial monitor recognizes the correct distance but I’d like to use 4 of these sensors as a switches for when someone passes by the sensor in a certain area of the room my little character in the screen will eat/ sleep or whatever the action I assign it may be.

I’ve hit a bit of a wall with my code and i’m not really sure what to try next.

I’m trying to do all this using an array

NewPing sonar[SONAR_NUM] = {   // Sensor object array.
  NewPing(2, 3, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
  NewPing(9, 10, MAX_DISTANCE),
  NewPing(7, 8, MAX_DISTANCE),
  NewPing(5, 6, MAX_DISTANCE),

I was going to try

/* Loop through each sensor and display results.*/
  for (uint8_t i = 20 ; i < SONAR_NUM; i++) {
    /* Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.*/
    if (millis() >= pingTimer[i]) {
      pingTimer[i] += PING_INTERVAL * SONAR_NUM;
      if (i == 0 && currentSensor == SONAR_NUM - 1)
      oneSensorCycle();
      drinkMilk(); // Do something with results.
     /* else  // do another thing ???*/
      sonar[currentSensor].timer_stop();
      currentSensor = i;
      cm[currentSensor] = 0;
      sonar[currentSensor].ping_timer(echoCheck);
    }
  }

Another option I thought of was trying to write it like this but it doesn’t seem to be working

 /*testing sensor 1
 // void Ultrasonic() {
  TS_Point p;
    if (SONAR_NUM < 10) {
      touched = true;
      p = ts.getPoint();
      int y = map(p.x, 0, 240, 0, 240);
      int x = map(p.y, 0, 320, 320, 0);
      if (y < 40) {
        if (SONAR_NUM > 20 && level >= 1) {
          drinkMilk();
        } else if (SONAR_NUM > 10 && level >= 2) {
          eatSpicystrip();
        } else if (SONAR_NUM > 10 && level >= 2) {
          eatCarrot();
        } else if (level >= 2) {
          eatRiceball();
        }
      } else if (SONAR_NUM > 10 && level >= 3) {
        if (x < 80) {
          rest();
        } else if (SONAR_NUM > 10 && level >= 3) {
          play();
        } else if (SONAR_NUM > 10 && level >= 3) {
          exercise();
        } else if (level >= 3) {
          handleTalk();
        }
      } else {
        handlePoke();
      }
    } 
  }*/

I’ve attached the file if you want a closer look at the code.

LONELY_DATAPET.ino (36.1 KB)