Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanRamaNoodles committed Jul 31, 2018
1 parent b897fe3 commit 139030d
Show file tree
Hide file tree
Showing 16 changed files with 1,051 additions and 593 deletions.
14 changes: 3 additions & 11 deletions README.md
Expand Up @@ -5,10 +5,7 @@ First Download [Tone library](https://github.com/bhagman/Tone) from bhagman. My
## Demonstration

Check out the video below for a Legend of Zelda music demostration. In the video, an Arduino Nano outputs two voices. The arduino uses a vibrating motor as a percussion instrument, and an RGB LED to add some fire to the show. The delay function is not used at all :)

[Click here for Video](https://youtu.be/uoHhlrqZYDI "Demonstration Video")

[Here is the link for the instructions from the video](https://create.arduino.cc/projecthub/nathan_ramanathan/music-without-delay-mp3-player-40e51b?ref=user&ref_id=185277&offset=0)
## Advantages
* This Arduino Library makes an Arduino board play music in the background while running your program(Assuming your code doesn't have any delay).
* **So you can view the Serial Monitor, display stuff on an OLED, and read buttons while this library plays your music in the background**
Expand All @@ -32,10 +29,7 @@ First Download [Tone library](https://github.com/bhagman/Tone) from bhagman. My
3. Choose the "Basics" sketch.
4. Attach a speaker with a 200 ohm resistor to pin 11, then attach the other end of the speaker to ground.
5. Upload the code.
6. Type "s" in the Serial monitor(which is set to 9600 baud rate)
* You should get something positive in return ;)
* If you got something in return, it proves that my library doesn't use Delay.
7. The comments in the code should be helpful. And try the other examples included with this library to learn to program without Delay.
6. The comments in the code should be helpful. And try the other examples included with this library to learn to program without Delay.

![alt text](https://raw.githubusercontent.com/nathanRamaNoodles/MusicWithoutDelay-LIbrary/master/MusicWithoutDelay.png "Schematic")

Expand Down Expand Up @@ -128,7 +122,7 @@ Let's use some examples to understand the format of the song file.
* Answer: char * name = ":b=160:c,d,e,f,g,a,b,c1";

6. Question: Play some dotted quarter notes
* Answer: char * name = ":d=4:4.c,4.d,.e";
* Answer: char * name = "::4.c,8.d,2.e";

7. Question: play a note every second
* Answer: char * name = ":d=4,b=60:c,p"; //bpm=60 means a quarter note = 1 second
Expand All @@ -144,7 +138,6 @@ Let's use some examples to understand the format of the song file.


# Functions
```
1. play(long cMillis, Tone tone1)// plays the song
2. pause(); //pauses and resumes song
3. newSong(char * p) //used to play a new song
Expand All @@ -162,5 +155,4 @@ Let's use some examples to understand the format of the song file.
15. isPaused() //returns true if song is paused
16. isNote() //returns true if song is playing a note
17. isBackwards() //returns true if song is playing backwards
18. skipTo(long index)//skips song to time suggested(must be in milliseconds) so 3 seconds into the song would be skipTo(3*1E3)
```
18. skipTo(long index)//skips song to time suggested
Binary file modified char song.PNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 55 additions & 12 deletions examples/Basic/Basic.ino
Expand Up @@ -6,15 +6,44 @@
Obviously, you can do other things while the song is being played.
For example, talk to Serial, read buttons, display images on an OLED screen, etc...
*/
//To learn more about this project go to https://github.com/nathanRamaNoodles/MusicWithoutDelay-LIbrary

/*MIT License
Copyright (c) 2018 nathanRamaNoodles
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
//To learn more about this project go to https://github.com/nathanRamaNoodles/MusicWithoutDelay
#include <MusicWithoutDelay.h>
#include <Tone.h> //https://github.com/bhagman/Tone
char *song = ":d=4:c,d,e,f,g,a,b,c1"; //the C major scale. This format is known as RingTone Transfer Language or RTTL(It was used by Nokia's phone company).
const char song[] PROGMEM = "::e,8f,8g,8a,8b,8c1,8d1,8e1"; //the C major scale. This format is known as RingTone Transfer Language or RTTL(It was used by Nokia's phone company).
const char song2[] PROGMEM = ":d=4:c,d,e,f";
const char song3[] PROGMEM = ":o=6,d=2:16a,16b,8a,4b";
const char song4[] PROGMEM = ":o=5,d=2:32g,32a,32b,32c";
MusicWithoutDelay instrument(song); //d=4 means that every note without a number in front of the letter is assumed to be a quarter note.
Tone myTone;
void setup() { //For details on the RTTL format, look at https://github.com/nathanRamaNoodles/MusicWithoutDelay-LIbrary documentation
MusicWithoutDelay instrument2(song2);
MusicWithoutDelay instrument3(song3);
MusicWithoutDelay instrument4(song4);
void setup() { //For details on the RTTL format, look at https://github.com/nathanRamaNoodles/MusicWithoutDelay documentation
// put your setup code here, to run once:
myTone.begin(11); //connect speaker with 200 ohm resistor to pin 11.
instrument.begin(CHB, TRIANGLE, ENVELOPE0, 0);
instrument2.begin(TRIANGLE, ENVELOPE0, 0);
instrument3.begin(TRIANGLE, ENVELOPE0, 0);
instrument4.begin(TRIANGLE, ENVELOPE0, 0);
Serial.begin(9600);
unsigned long t = instrument.getTotalTime(); //spits out total time in milliseconds

Expand All @@ -23,13 +52,15 @@ void setup() { //For details on the RTTL format, l

void loop() {
// put your main code here, to run repeatedly:
unsigned long cMillis = millis(); //I know millis() can be implemented in my library,
instrument.play(cMillis, myTone); //but its important to recognize that this library depends
instrument.play(); //but its important to recognize that this library depends
instrument2.play();
instrument3.play();
instrument4.play();
if (instrument.isEnd()) { //on your main code not having delay(). Also, it increases stability, so your welcome :D
instrument.reverse(); //reverses song when end is reached
}
if (instrument.isStart()) {
instrument.pause(); //stops the song when beginning is reached while song was played backwards
// instrument.pause(); //pauses song
// instrument2.pause();
// instrument3.pause();
// instrument4.pause();
}
if (Serial.available()) {
char str = Serial.read();
Expand All @@ -38,6 +69,18 @@ void loop() {
//instrument.skipTo(instrument.getTotalTime() * (0.50)); //skip to halfway point
Serial.println("What's it to ya? I don't use delay, and you shouldn't either.\n Star this project on Github, and spread this good news to others.");
break;
case '1': //type 's' in Serial monitor.
instrument.mute();
break;
case '2': //type 's' in Serial monitor.
instrument2.mute();
break;
case '3': //type 's' in Serial monitor.
instrument3.mute();
break;
case '4': //type 's' in Serial monitor.
instrument4.mute();
break;
}
}
}
177 changes: 0 additions & 177 deletions examples/Legend_Of_Zelda/Legend_Of_Zelda.ino

This file was deleted.

44 changes: 35 additions & 9 deletions examples/Percussion/Percussion.ino
@@ -1,27 +1,53 @@
/*Example for the MusicWithoutDelay Library by Nathan Ramanathan. nathan6ramanathan@gmail.com
This sketch demostrates the isNote function's advantage. It can be used for percussion :D
It plays a small section of the Entertainer Song.
This sketch demostrates the skipTo function's advantage. It can skip to any point of the song :D
It plays a small section of the legend of Zelda Song.
Obviously, you can do other things while the song is being played.
For example, talk to Serial, read buttons, display images on an OLED screen, etc...
Pressing either button on pin 2 or 3 causes the song to skip to the beginning or anywhere.
This is by far the most complex, beautiful, mathematical function I have created. :')
Use skipTo(long) wisely
*/

/*
MIT License
Copyright (c) 2018 nathanRamaNoodles
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// More info at https://github.com/nathanRamaNoodles/MusicWithoutDelay-LIbrary
#include <MusicWithoutDelay.h>
#include <Tone.h> //https://github.com/bhagman/Tone
Tone myTone;
char *song = "Entertainer:d=4,o=5,b=140:8d,8d#,8e,c1,8e,c1,8e,2.c1,8c1,8d1,8d#1,8e1,8c1,8d1,e1,8b,d1,2c1,p,8d,8d#,8e,c1,8e,c1,8e,2.c1,8p,8a,8g,8f#,8a,8c1,e1,8d1,8c1,8a,2d1";
const char song[] PROGMEM = {"Entertainer:d=4,o=5,b=140:8d,8d#,8e,c1,8e,c1,8e,2.c1,8c1,8d1,8d#1,8e1,8c1,8d1,e1,8b,d1,2c1,p,8d,8d#,8e,c1,8e,c1,8e,2.c1,8p,8a,8g,8f#,8a,8c1,e1,8d1,8c1,8a,2d1"};
MusicWithoutDelay drum(song);
#define motor A0 //vibrating motor attached to AnalogPin 0
#define motor A2 //vibrating motor attached to AnalogPin 0
unsigned long motorMillis = 0;
void setup() {
// put your setup code here, to run once:
pinMode(motor, OUTPUT); //percussion instrument
myTone.begin(11);
drum.begin(CHB, TRIANGLE, ENVELOPE0, 0);
}

void loop() {
// put your main code here, to run repeatedly:
unsigned long cMillis = millis();
drum.play(cMillis, myTone);
drum.play();
if (cMillis - motorMillis >= 50) {
digitalWrite(motor, LOW);
}
Expand Down

0 comments on commit 139030d

Please sign in to comment.