User:Fabien Labeyrie/Clapping Arduino Modulo: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 1: Line 1:
==Clapping Arduino==
==Clapping Arduino==


The following exercise puts [http://en.wikipedia.org/wiki/Steve_Reich Steve Reich] in an [http://en.wikipedia.org/wiki/Arduino italian chip], using its ''tone'' functionality. As a result, it should be able to play the [http://en.wikipedia.org/wiki/Clapping_Music clapping music] by itself.   
The following exercise puts [http://en.wikipedia.org/wiki/Steve_Reich Steve Reich] into an [http://en.wikipedia.org/wiki/Arduino italian chip], using its ''tone'' functionality. As a result, it should be able to play the [http://en.wikipedia.org/wiki/Clapping_Music clapping music] by itself.   


===Version I :  two speakers and two loops===
===Version I :  two speakers and two loops===
This code got a few inspiration 
====How does it work ?====
The ''Clapping music'' consists in one pattern being played and shifted by two people. We will use two speakers to differentiate the two musical lines and to produce a stereo effect. The Arduino board will dispatch the ''tone'' information to the speakers thanks to two nested ''for'' loops and two ''if'' conditions. <ref>This code couldn't have been completed without the help of [http://pzwart3.wdka.hro.nl/wiki/User:Birgit_bachler Birgit].</ref>
 
=====Technologies involved=====
The Arduino program is very close to [http://en.wikipedia.org/wiki/C_%28programming_language%29 C].
 
=====Steps=====
*Tone function in arduino can't play note simultaneously, so we have to trick human sound perception in order to make us believe two very close sounds are played at the same time.
*Tone function in arduino can't play note simultaneously, so we have to trick human sound perception in order to make us believe two very close sounds are played at the same time.


Line 57: Line 63:
}
}
</source>
</source>
<references />

Revision as of 13:18, 7 November 2010

Clapping Arduino

The following exercise puts Steve Reich into an italian chip, using its tone functionality. As a result, it should be able to play the clapping music by itself.

Version I : two speakers and two loops

How does it work ?

The Clapping music consists in one pattern being played and shifted by two people. We will use two speakers to differentiate the two musical lines and to produce a stereo effect. The Arduino board will dispatch the tone information to the speakers thanks to two nested for loops and two if conditions. [1]

Technologies involved

The Arduino program is very close to C.

Steps
  • Tone function in arduino can't play note simultaneously, so we have to trick human sound perception in order to make us believe two very close sounds are played at the same time.

It's fucking too late to do some wiki stuff so I'm gonna continue tomorrow

Code

int speakerHigh = 8;
int speakerLow = 7;
int noteValue = 3000;

int theDelay = 10;
 
char pat[] = "xxx xx x xx ";
int patlen = strlen(pat);
 
void setup(){}
 
void loop (){

  for (int iLine=0; iLine<patlen; iLine++){
    
    // The following loop will be performed completly first, then launched again by the previous one.
    for (int iBeat=0; iBeat<patlen; iBeat++){
    
        // Each beat will be assigned a number value
        int iNote = iBeat+iLine;
        
        
          // When the number value is bigger than 11, it's been resetted to 0 
          if (iNote > (patlen-1)){
            iNote = iBeat-patlen+iLine;
          }

        // Channel one 
        if (pat[iBeat] == 'x') {
          // We have to shut the other speaker in order to make this one play
          noTone(speakerHigh);
          tone(speakerLow, noteValue, theDelay);
          delay(theDelay);
        }
        // The second channel is played 10 milliseconds after the first, simulating a simultaneous playing by using a higher pitched note.
        if (pat[iNote] == 'x') {
          noTone(speakerLow);
          tone(speakerHigh, noteValue, theDelay);
        }
 
    delay(theDelay*theDelay);    
    }  
  }
}
  1. This code couldn't have been completed without the help of Birgit.