Tone and noTone function

Hey,

When I tried tone and noTone function on ESP it doesn't work. So what are similar methods for ESP of these?

When I tried tone and noTone function on ESP it doesn’t work.

Did the code fail to compile? Did the tone() call let the smoke out of something?

“It doesn’t work” is useless information.

I tied this code:
@@ -0,0 +1,37 @@
#include <ALKS.h>

//Add requed files
#include “pitches.h”
#include “themes.h”

void setup(){
}

void loop(){

//This code runs only on Esp
#if defined(ESP8266) || defined(ESP32)
for (int thisNote = 0; thisNote < (sizeof(Pirates_note)/sizeof(int)); thisNote++) {

int noteDuration = 1000 / Pirates_duration[thisNote];
ledcWriteTone(PIEZO1, Pirates_note[thisNote], noteDuration);

int pauseBetweenNotes = noteDuration * 1.05; //Tempo. ou can set your own.
delay(pauseBetweenNotes);
noTone(PIEZO1); //Pause
}
#endif

//For cycle which plays melod itself
for (int thisNote = 0; thisNote < (sizeof(Pirates_note)/sizeof(int)); thisNote++) {

int noteDuration = 1000 / Pirates_duration[thisNote];
tone(PIEZO1, Pirates_note[thisNote], noteDuration);

int pauseBetweenNotes = noteDuration * 1.05; //Tempo. ou can set your own.
delay(pauseBetweenNotes);
noTone(PIEZO1); //Pause
}

}

Travis ci shows me this error: /home/travis/.arduino15/packages/esp32/hardware/esp32/1.0.1/cores/esp32/esp32-hal-ledc.h:32:13: note: declared here
double ledcWriteTone(uint8_t channel, double freq);
^
buzzerSongs_Pirates:22: error: ‘noTone’ was not declared in this scope
noTone(PIEZO1); //Pause
^
buzzerSongs_Pirates:30: error: ‘tone’ was not declared in this scope
tone(PIEZO1, Pirates_note[thisNote], noteDuration);
^
buzzerSongs_Pirates:34: error: ‘noTone’ was not declared in this scope
noTone(PIEZO1); //Pause
^
exit status 1

TomasRoj:
When I tried tone and noTone function on ESP it doesn't work.

It is Expressif that are responsible for the support of the ESP under the Arduino IDE.

There was an issue about their implementation not including tone() raised sometime back and there seemed to be a promise that it would be implemented ...... sometime.

So there is no way how to do it?

TomasRoj:
When I tried tone and noTone function on ESP

There is no such thing as “ESP”. From the error output you posted, I can see you are compiling for ESP32. Is is really so much effort for you to type those two extra characters? If you want to have any success in programming and electronics, you need to train yourself to be very precise. The compiler isn’t going to say “it’s cool, I knew you meant ESP32”. It’s best if you use the same approach where asking for help here on the forum. It takes only a second two type a few extra characters, but being precise could end up saving a lot of time by avoiding confusion and requests for additional information.

TomasRoj:
I tied this code:

Please use code tags when you post code or warning/error messages. To do this, click the </> button on the forum toolbar, then paste the text you want to be in the code tags. Finally, move the cursor out of the code tags before adding any additional text you don’t want to be in the code tags. If your browser doesn’t show the posting toolbar, then you can manually add the code tags like this:
[code]``[color=blue]// your code is here[/color]``[/code]

The reason for doing this is that, without code tags, the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier for us to read your code and to copy it to the IDE or editor.

Using code tags and other important information is explained in the “How to use this forum” post. Please read it.

When your code requires a library that’s not included with the Arduino IDE please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

TomasRoj:
what are similar methods for ESP of these?

From your previous thread:

TomasRoj:
But there isnt function tone() for esp. One guy said that we can make #ifdef in arduino code and use ledcWriteTone() func.

So some mysterious “one guy” already tried to help you with this question. It seems you found a replacement for tone() on the ESP32 with ledcWriteTone(), but then for some reason you decided to still call tone() in another part of your code, even though you know full well that’s not going to work on ESP32. It seems you didn’t spend enough time studying the information about conditional preprocessor directives as I recommended in your other thread. Go back and read it all over again more carefully. This time, pay more attention to the part about #else.

Since you already know there is no tone() on ESP32, what makes you think there would be be a noTone()?

Since you already know there is no tone() on ESP32, what makes you think there would be be a noTone()?

Well, "stop making that noise that you aren't making" would certainly be a easy function to implement.