Multiple Ultrasonic Sensors

The Easy Robot for Everyone!

Multiple Ultrasonic Sensors

Postby torstenvolk » Sat Aug 13, 2016 4:13 am

What do I need to change to be able to enable Sparki.h and use multiple ultrasonic sensors. Currently, I can only get the old OR the new sensor to work: When I #include Sparki.h the below code simply will not work. Can anyone tell me what I need to change in the sparki library to get both sensors to work?

Here's the code I'm using. I have also tried this using ports 0 and 1 and the result is always the same: When I don't #include Sparki.h, the 2nd sensor works, but when I put back Sparki.h, it doesn't. Where is the conflict??? Thanks so much for your help!

#define trigPin2 3
#define echoPin2 2
#include <Sparki.h>
void setup()

{

Serial.begin(9600);

pinMode(trigPin2, OUTPUT);

pinMode(echoPin2, INPUT);

}

void loop()

{

int duration2, distance2;

digitalWrite(trigPin2, HIGH);

delayMicroseconds(2000);

digitalWrite(trigPin2, LOW);

duration2 = pulseIn(echoPin2, HIGH);

distance2 = (duration2/2) / 29.1;

Serial.println(distance2);

Serial.print("cm");

delay(500);

}
torstenvolk
 
Posts: 1
Joined: Sat Aug 13, 2016 4:01 am

Return to Sparki

Who is online

Users browsing this forum: No registered users and 3 guests

cron