#define SONAR_NUM     2 // Number or sensors.
#define MAX_DISTANCE 200 // Max distance in cm.
#define PING_INTERVAL 100 // Milliseconds between pings.
bool flag = 0;   
bool flag2 = 0;
unsigned long pingTimer[SONAR_NUM]; // When each pings.
unsigned long avgping0;
unsigned long avgping1;
unsigned int cm[SONAR_NUM]; // Store ping distances.
uint8_t currentSensor = 0; // Which sensor is active.
Average<unsigned int> ave(5);
Average<unsigned int> ave1(5);
 
NewPing sonar[SONAR_NUM] = { // Sensor object array.
  NewPing(3, 3, MAX_DISTANCE),
  NewPing(6, 6, MAX_DISTANCE),
 };
 
 
void setup() {
  Serial.begin(9600);
  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() {
  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?
Beispiel #2
0
#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).
#define trigPin1 5 // yellow wire
#define echoPin1 6 // white wire
#define trigPin2 10 //Yellow wire
#define echoPin2 11 //White wire
//if the car's wheels are going backwards. Edit these pins as needed
const int motor_front[] = {2, 4}; //Front Pins
const int motor_back[] = {7, 8}; //Rear Pins
int rangeFront = 0;
int rangeWall = 0;
//rangeF[1] results from pins 9 and 6
//rangeF[2] results from pins 12 and 13
//int wayToClose = 800;

NewPing sonar[SONAR_NUM] = {     // Sensor object array.
  NewPing(trigPin1, echoPin1, MAX_DISTANCE), //Front
  NewPing(trigPin2, echoPin2, MAX_DISTANCE) //Side
};//endArray


void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // Setup motors
  int i;
  //setting up the motor contols
  for(i = 0; i < 2; i++){
    pinMode(motor_back[i], OUTPUT);
    pinMode(motor_front[i], OUTPUT);
    //setting up the SRF05
  }//end for
Beispiel #3
0
//#include <TSL2561.h>

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

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.

TSL2561 tsl_1(TSL2561_ADDR_HIGH);
TSL2561 tsl_2(TSL2561_ADDR_LOW);
TSL2561 tsl_3(TSL2561_ADDR_FLOAT);

NewPing sonar[SONAR_NUM] = {     // Sensor object array.
  NewPing(14, 15, MAX_DISTANCE),
  NewPing(8, 9, MAX_DISTANCE),
  NewPing(10, 11, MAX_DISTANCE),
  NewPing(12, 13, MAX_DISTANCE) // Each sensor's trigger pin, echo pin, and max distance to ping.
};

void setup() {

  Serial.begin(9600);

  tsl_1.begin();
  tsl_2.begin();
  tsl_3.begin();

  tsl_1.setGain(TSL2561_GAIN_16X); // low light gain
  tsl_2.setGain(TSL2561_GAIN_16X);