From 07e16b1c0772b15d486625edbcec6dd7c865798e Mon Sep 17 00:00:00 2001 From: Nathan Ramanathan Date: Wed, 12 Sep 2018 16:11:10 -0500 Subject: [PATCH] tutorial --- README.md | 18 +++-- .../songs/song_with_MOD/song_with_MOD.ino | 80 +++++++++---------- 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index c8771be..746c247 100644 --- a/README.md +++ b/README.md @@ -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 -- [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) @@ -74,6 +77,7 @@ 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... @@ -81,8 +85,12 @@ This library should work for the following boards: * 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). diff --git a/examples/songs/song_with_MOD/song_with_MOD.ino b/examples/songs/song_with_MOD/song_with_MOD.ino index ac79ffd..2d5f9af 100644 --- a/examples/songs/song_with_MOD/song_with_MOD.ino +++ b/examples/songs/song_with_MOD/song_with_MOD.ino @@ -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); @@ -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(); @@ -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