Giter VIP home page Giter VIP logo

Comments (3)

robsoncouto avatar robsoncouto commented on August 23, 2024

Hi @Snooze4 , if you are using Arduino to program the esp32, there should not be a problem.
It's highly unlikely that it is a library problem, unless you installed some library that changed the default behaviour of tone().
Anyways, you should not need any library to run this code. It only depends on standard arduino functions.

Please check that you are using the correct pin and also that the pin you are using can be used for this purpose. You can change the pin number in the code, please have a look.

Also, I don't have an Esp32, so i can not confirm it works. I don't see why it should not though.

from arduino-songs.

Snooze4 avatar Snooze4 commented on August 23, 2024

Well esp32 does not understand tone.

from arduino-songs.

umsmin avatar umsmin commented on August 23, 2024

Sorry for my late help.
But I think it will maybe help others.

It works on ESP32 with a little library and modifications.

(https://github.com/lbernstone/Tone32)

In the example you see how to use it, but for now.

Add this on top of the code:

// The tone library for ESP32
#include <Tone32.h>

// we use the PWM channel 0 for here
int buzzerChannel = 0;

Change this:

tone(buzzer, pgm_read_word_near(melody+thisNote), noteDuration * 0.9);

To this:

tone(buzzer, pgm_read_word_near(melody+thisNote), noteDuration * 0.9, buzzerChannel);

From this:

} else if (divider < 0) {
      // dotted notes are represented with negative durations!!
      noteDuration = (wholenote) / abs(divider);
      noteDuration *= 1.5; // increases the duration in half for dotted notes
}

To this

else if (divider < 0) {
      // dotted notes are represented with negative durations!!
      noteDuration = (wholenote) / abs(divider);
      noteDuration = noteDuration * 1.5; // increases the duration in half for dotted notes
}

And also this:

noTone(buzzer);

To this:

noTone(buzzer, buzzerChannel);

That's it.

from arduino-songs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.