Skip to content

Commit

Permalink
tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanRamaNoodles committed Sep 12, 2018
1 parent 980baa8 commit 07e16b1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 45 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# MusicWithoutDelay Library(v3.5.0)
# MusicWithoutDelay Library(v3.5.1)

[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HN6V9GRCU4L6U)

An Arduino Library to play infinite polyphonic notes with full control over volume, pitch, and . . . music :D
**Description**: A non-blocking Arduino Library to play infinite polyphonic notes with full control over volume, pitch, modulation, and . . . music :D
* [Videos here](https://github.com/nathanRamaNoodles/MusicWithoutDelay-LIbrary#demonstration)
* [Quick start here](https://github.com/nathanRamaNoodles/MusicWithoutDelay-LIbrary#quick-start)
* [What's new?](https://github.com/nathanRamaNoodles/MusicWithoutDelay-LIbrary#updates)
* This library was inspired by [Bhagman's RTTL Arduino sketch](https://github.com/bhagman/Tone/blob/master/examples/RTTTL/RTTTL.pde) and [Dzlonline's synth engine](https://github.com/dzlonline/the_synth)

## Table of Contents
<!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:undefined orderedList:0 -->

- [MusicWithoutDelay Library](#musicwithoutdelay-libraryv350)
- [MusicWithoutDelay Library](#musicwithoutdelay-libraryv351)
- [Compatibility](#compatibility)
- [Change Teensy pins](#new-you-can-change-the-teensys-output-pin-3rd-generation-only)
- [How to Change Polyphony](#how-to-change-polyphony)
Expand Down Expand Up @@ -74,15 +77,20 @@ This library should work for the following boards:
* This library has been upgraded to version 3.5.1
* previous versions [found here](https://github.com/nathanRamaNoodles/MusicWithoutDelay-LIbrary/releases).
* Improvements
* Added videos to demonstration
* Created an anti-clip algorithm that adjusts the Volume to avoid static noise :)
* more to come...

## Demonstration

* v1.0.0 demo
* Check out [this video](https://youtu.be/uoHhlrqZYDI) for a Legend of Zelda music demonstration. 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 :)
* v3.0.0 demo
* coming soon...
* v3.5.1 demo
* [Introduction to Library](https://www.youtube.com/watch?v=SnHucYUKfMM)
* [How to change max note polyphony](https://www.youtube.com/watch?v=N2jZ9EwdiJM)
* [Play Music](https://www.youtube.com/watch?v=3NRbqMfplmI)
* [Do stuff while playing music](https://www.youtube.com/watch?v=U37jHJSXU2g&t=206s)
* [30-note polyphony on Teensy](https://www.youtube.com/watch?v=L077CAO5ABE)

## 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).
Expand Down
80 changes: 40 additions & 40 deletions examples/songs/song_with_MOD/song_with_MOD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool recursion, isHeld;
int sustain[3] = {1, 1, 1};

void setup() {
// Serial.begin(9600);
Serial.begin(9600);
pinMode(potPin, INPUT);
buzzer.begin(CHA,RAMP, ENVELOPE0, 0); //CHB means pin 3 on Arduino UNO, CHA means pin 11, DIFF means both
buzzer2.begin(RAMP, ENVELOPE0, 0);
Expand All @@ -56,10 +56,10 @@ void setup() {
buzzer.overrideSustain(true);//must override built-in sustains to modify song's sustains at runtime
buzzer2.overrideSustain(true);
buzzer3.overrideSustain(true);
// Serial.println(F("Type '1','2', or '3' to pause the corresponding instrument. If you let one of the instruments to finish, the arduino will restart from the beginning."));
// Serial.println(F("Type more than one number to pause multiple instruments"));
// Serial.println(F("Also, type 'b' to play the song backwards, and press `z`, `x`, and `c` to hear the sustains corresponding to each instrument"));
// Serial.print(F("TotalTime: ")); Serial.print(buzzer.getTotalTime() / 1E3); Serial.println(F(" seconds"));
Serial.println(F("Type '1','2', or '3' to pause the corresponding instrument. If you let one of the instruments to finish, the arduino will restart from the beginning."));
Serial.println(F("Type more than one number to pause multiple instruments"));
Serial.println(F("Also, type 'b' to play the song backwards, and press `z`, `x`, and `c` to hear the sustains corresponding to each instrument"));
Serial.print(F("TotalTime: ")); Serial.print(buzzer.getTotalTime() / 1E3); Serial.println(F(" seconds"));
}
void loop() {
btn.read();
Expand Down Expand Up @@ -97,41 +97,41 @@ void loop() {
}
if (!save)
proper_Restart(); //corrects overlapping at end of song
// if (Serial.available()) {
// char str = Serial.read();
// switch (str) {
// case '1': //type '1' in Serial monitor.
// buzzer.pause(!buzzer.isPaused());
// (buzzer.isPaused()) ? count++ : count--; //ternary operator is faster than if/else statements.
// (count == NUM) ? save = true : save = false;
// break;
// case '2': //type '2' in Serial monitor.
// buzzer2.pause(!buzzer2.isPaused());
// (buzzer2.isPaused()) ? count++ : count--;
// (count == NUM) ? save = true : save = false;
// break;
// case '3': //type '3' in Serial monitor.
// buzzer3.pause(!buzzer3.isPaused());
// (buzzer3.isPaused()) ? count++ : count--;
// (count == NUM) ? save = true : save = false;
// break;
// case 'b':
// backwards();
// break;
// case 'z':
// sustain[0] = !sustain[0];
// buzzer.setSustain(sustain[0]);
// break;
// case 'x':
// sustain[1] = !sustain[1];
// buzzer2.setSustain(sustain[1]);
// break;
// case 'c':
// sustain[2] = !sustain[2];
// buzzer3.setSustain(sustain[2]);
// break;
// }
// }
if (Serial.available()) {
char str = Serial.read();
switch (str) {
case '1': //type '1' in Serial monitor.
buzzer.pause(!buzzer.isPaused());
(buzzer.isPaused()) ? count++ : count--; //ternary operator is faster than if/else statements.
(count == NUM) ? save = true : save = false;
break;
case '2': //type '2' in Serial monitor.
buzzer2.pause(!buzzer2.isPaused());
(buzzer2.isPaused()) ? count++ : count--;
(count == NUM) ? save = true : save = false;
break;
case '3': //type '3' in Serial monitor.
buzzer3.pause(!buzzer3.isPaused());
(buzzer3.isPaused()) ? count++ : count--;
(count == NUM) ? save = true : save = false;
break;
case 'b':
backwards();
break;
case 'z':
sustain[0] = !sustain[0];
buzzer.setSustain(sustain[0]);
break;
case 'x':
sustain[1] = !sustain[1];
buzzer2.setSustain(sustain[1]);
break;
case 'c':
sustain[2] = !sustain[2];
buzzer3.setSustain(sustain[2]);
break;
}
}

}
void proper_Restart() { //this method avoids accidental overlapping in songs with different total times
Expand Down

0 comments on commit 07e16b1

Please sign in to comment.