Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

NewPing library and tone function in one program??

Status
Not open for further replies.

Tanmay_Karmakar

New Member
Using NewPing library for a project but stuck cause I can't use tone function in that. "Error: Id returned 1 exit status......"
Why is it happening?
What is the solution?
 

Attachments

  • Screenshot_20200722-164430.jpg
    Screenshot_20200722-164430.jpg
    281.9 KB · Views: 420
Can you post ALL your code, not just snippets.

Mike.
Edit, don't post a picture of your code, post the text between code tags.
 
Last edited:
Can you post ALL your code, not just snippets.

Mike.
Edit, don't post a picture of your code, post the text between code tags.
Ok.. here it is.. without just the tone function the program compiles fine..
Code:
#include "NewPing.h"
#define echoPin 7
#define trigPin 6
#define buzzPin 8
unsigned int dly=300;
NewPing distance(trigPin, echoPin, 500);
void setup()
{
    pinMode(buzzPin, OUTPUT);
   Serial.begin(115200);
}
void loop()
{
float cm=distance.convert_cm(distance.ping_median());
Serial.println(" Subject is ");
Serial.print(cm);
Serial.print(" cm away");
    noTone(buzzPin);
    while(cm<300)
    {
       unsigned int gap=(dly-cm)*50;
        tone(buzzPin, gap, 400);
    }
}
 
tone ( pin, frequency, duration); It specifically says unsigned int, you are passing a float.. cast it to see if it fixes

tone(buzzpin, round(gap), 400); or.. tone(buzzpin, (int)gap, 400);
 
tone ( pin, frequency, duration); It specifically says unsigned int, you are passing a float.. cast it to see if it fixes

tone(buzzpin, round(gap), 400); or.. tone(buzzpin, (int)gap, 400);
Thanks.. it seems to be a silly mistake... But still the problem remains..
 
I've found the culprit, it's that they both use the same interrupt "vector__7". That was in the error msg, anyhow I didn't saw that earlier.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top