You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*I don't know where to go for a forum, but this should be a super quick and simple question.
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............................................................................
}
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!
The text was updated successfully, but these errors were encountered:
This is a fork of NewPing - not the original library. If you just want the, then the NewPing original is probably better maintained.
In this fork, the user specified function that is passed to ping_timer, receives an additional argument, a pointer to the NewPing instance that called the function.
So to work with this version, the function signature needs to be
*I don't know where to go for a forum, but this should be a super quick and simple question.
What is going wrong?
all code pertaining to the ultrasounds(basically a copy of what you had in the examples):
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!
The text was updated successfully, but these errors were encountered: