Skip to content

error with echoCheck visual studio code #1

@Sorin-Jayaweera

Description

@Sorin-Jayaweera

*I don't know where to go for a forum, but this should be a super quick and simple question.

image

What is going wrong?

all code pertaining to the ultrasounds(basically a copy of what you had in the examples):


#include <NewPing.h>

#define SONAR_NUM     2 // Number of sensors.
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).

const byte SONARECHOPIN1 = 23; 
const byte SONARTRIGPIN1 = 22;

const byte SONARECHOPIN2 = 21;
const byte SONARTRIGPIN2 = 20;

/*sonar 1 pins:
unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
unsigned int cm[SONAR_NUM];         // Where the ping distances are stored.
uint8_t currentSensor = 0;          // Keeps track of which sensor is active.

char *sonarLabel[] = {"ultra1", "ultra2", "ultra3"};

const int ultrasoundSamplingTimer = 200; // check very often
double lastUltrasoundSample;

void readUltrasound();
void echoCheck();
void oneSensorCycle();


void setup() {
   pingTimer[0] = millis() + 75;           // First ping starts at 75ms, gives time for the Arduino to chill before starting.
   for (uint8_t i = 1; i < SONAR_NUM; i++){ // Set the starting time for each sensor.
    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
   }
   
}

void loop() {  
  if(currentTime - lastUltrasoundSample >= ultrasoundSamplingTimer){
    Serial.println("readUltraSound");
    lastUltrasoundSample = millis();    
    readUltrasound();    
  }
}

void readUltrasound(){
 for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through all the sensors.
    if (millis() >= pingTimer[i]) {         // Is it this sensor's time to ping?
      pingTimer[i] += PING_INTERVAL * SONAR_NUM;  // Set next time this sensor will be pinged.
      if (i == 0 && currentSensor == SONAR_NUM - 1) oneSensorCycle(); // Sensor ping cycle complete, do something with the results.
      sonar[currentSensor].timer_stop();          // Make sure previous timer is canceled before starting a new ping (insurance).
      currentSensor = i;                          // Sensor being accessed.
      cm[currentSensor] = 999;                      // Make distance zero in case there's no ping echo for this sensor.
      sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
    }
  }
}


void echoCheck() { // If ping received, set the sensor distance to array.
  if (sonar[currentSensor].check_timer()){
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
  }
}

void oneSensorCycle() { // Sensor ping cycle complete, do something with the results.
 /* display.setCursor(0,cursorLine2);
  display.print("                    ");//clear the line only
  display.display();
*/
//ultrasound has pinged, now check distance and do object avoidence............................................................................
}

image

This should be a relatively quick and easy fix, just an issue with Visual Studio Code or something. Thank you! I love you library, it's a major component of my project, and without it I wouldn't be able to do this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions