Updates from hilalkoyuncu Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    hilalkoyuncu 9:09 pm on March 3, 2011 Permalink | Reply  

    Romantic Lighting Sensor(Exercise 1) 

    “WIRELESS NETWORKING IS NOT NEARLY AS TRICKY AS NAVIGATING ROMANCE.”~Robert Faludi

    But here is what you can do:

    • Set up your COORDINATOR to API mode on X-CTU:


    • Note that after setting up your coordinator firmware to API mode on X-CTU, you can only configure your PAN ID(your chosen address),  ATDH(0013a200) and ATDL(the remainder of your routers address) on X-CTU as the following:

    • Then click Write button to save changes.
    • Set up your ROUTER on Coolterm:

    +++

    ATID (Same as Coordinator ATID)

    ATDH0013a200

    ATDL ( Remainder of Coordinator’s address)

    ATJV1 ( To ensure that router attempts to rejoin the coordinator on startup.)

    ATD02 ( To put pin “0” in analog mode.)

    ATIR64 [ To set up the sample rate to 10 times/second—1000ms/10=100ms=64(hex)]

    ATWR (To save the settings.)

    • Wiring ————ROUTER:

    • Wiring ————COORDINATOR:

     

    PITFALLS:

    Make sure your voltage regualtor is plugged in properly. If you have the LM1086CT the pin where etched circle is located would be GROUND, the middle one would be OUTPUT and the third one would be INPUT.

    Make sure your breakboard has the RIGHT pins connected to Arduino.

    When its all done, upload the first code that Kate posted.

    If everything is correctly hooked up you will observe this:

     
  • Unknown's avatar

    hilalkoyuncu 1:51 am on February 18, 2011 Permalink | Reply  

    larry-in the closet… 

    This is Larry, he lives in the closet but he wants to “come out”. He has 8 different states of emotion which would be triggered if certain(14 !!) scenarios are active.

    Larry has dementia, his memory  resets it self every 12 hours.

    He cannot stand to be out for so long because he is socially awkward. The user has to give him a balanced attention to keep him content.

    If he doesn’t get enough attention he cuts his wrists and blames the user for it.

     (More ...)
     
    • Yury Gitman's avatar

      makingtoys 3:27 am on February 18, 2011 Permalink | Reply

      code goes into “read more” section of your post. please edit the post to that format.

  • Unknown's avatar

    hilalkoyuncu 1:28 am on February 18, 2011 Permalink | Reply  

    Toy fair 

    Even though they weren’t interactive the giant microbes were interesting to me because of my educational background. In the future I would like  to create electronically interactive biological forms.This was very inspirational to me.

    I liked geolovepalz, I think it was  smart in a was to engage kids in physical activities.

    I liked mugo because, it was simple and efficient, its a usb stick where u can store data and it also is a mp3 player. Its tiny and visually appealing.

     

     

     

     

     
  • Unknown's avatar

    hilalkoyuncu 9:43 pm on February 10, 2011 Permalink | Reply  

    Companions 

    For my companion project I have three characters: the wingman, mini-me and the yogi.

    The wingman:

    The wingman goes out with the user to bars and helps her/him pick up boys/girls.

    The user will be wearing a wrist band that has a GSR which will communicate with the wingman and let him/her know that the user is psychologically and/or physiologically aroused. The hall effect sensor on the wingman will determine if there are any people close to the user when GSR is on, if there aren’t people around it will make flirty noises and lights to draw attention to the user.

    Light sensor will help the wingman to be louder/ more aggressive with its audio/visual responses assuming that the user is in a dark and loud place (a club) to draw attention more effectively.

    The wingman will stop interacting once the proper proximity between the user and a person is achieved.

    Mini-me

    Mini-me is a clone of the user, it experiences what the user experiences physically and responds to the user depending on how the user treats her/his body.

    Mini-me has a motion detector and a light sensor and he/she sits on the user’s bed to determine the sleep cycle of the user.

    The user is wearing a bracelet that has a pulse sensor and a smoke detector to detect wether the user smokes and exercises.

    When the user comes home the data from the bracelet will be transfered to mini-me via a wireless connection.

    Depending on how the user treated her/his self mini me posts a status update about the user/ itself(since its a mini version of the user:) on facebook.

    The Yogi:

    The  user will be wearing a belt with a flex sensor and a bracelet with a pulse sensor or a GSR.

    The flex sensor is in charge of determining if the user’s spine is upright, to establish a good flow of energy throughout the body. The pulse montior/ GSR will determine if the user is in a calm state and is breathing correctly.

    The yogi has a light sensor  this will alert the user to dim the light to create a better ambience for meditation and it will go off again to alert the user that the meditation is over .

    The yogi will give the user directions for her/him to keep a nice spine and to breath properly to achieve a good meditative state.

    The yogi will respond with sound only.

     
  • Unknown's avatar

    hilalkoyuncu 11:22 pm on February 7, 2011 Permalink | Reply  

    Victor and Hilal, photo resistor prototype 1 

    For our photo resistor device we decided to make two stoners who smoke different kinds of weeds, one GOOD weed, one BAD weed.

    Ours stoners would communicate how high they are by reflecting their state of mind in music.

    My part of the project was to design the BAD weed smoker.

    1) Explain the code in a nutshell: logic, important parts:

    The code was written so that it the stoner will get high as he smokes more weed. Lighting up the joint would intuitively establishes this. The stoner is always in a state of being moderately high, cause he smokes all the time. When he sobers up he would feel at the lowest level of his emotions, apathetic to world almost.

    To create the illusion of life, meaning life happens gradually, introduced the component of time into our code. To switch from the last state of emotion(blitzed) to the state of no emotion(sleep), the user has to generate the last state for a period of time(2 seconds) in order for it to finalize the program.

    This was originally planned to be applied to switch each state of emotion to the next one, hopefully this will be accomplished in the next iteration.

    2)what did you do that you feel is new, non obvious and useful.

    We felt that using the light sensor to create an analogy of a lighter, even though was obvious, it was innovative. I am not sure if anyone has tried to do it before. In any case this actually made the interaction better because of affordances, how would a user possibly interact with a smoker if he/she is given a lighter?

    It is a useful design to create entertainment.

    We hope to refine the code and the prototype further.

    Here is a link to the prototype:

    http://vimeo.com/19786084

    Here is the code:

    
    
    //*hilal koyuncu*//**shwag smoker-2011**
    
    #include "hilal_pitches.h"
    
    const int sensorPin = 0;
    int sensorValue = 0;     int sensorMin; // sensor minimum, discovered through experimentint sensorMax; // sensor maximum, discovered through experimentint time;//time that has passed since the melody started playing
    int lullaby[] = { NOTE_G6, NOTE_G6,  NOTE_AS6,  NOTE_G6, NOTE_G6,  NOTE_AS6,  NOTE_G6, NOTE_AS6, NOTE_DS7,  NOTE_D7, NOTE_C7, NOTE_C7,   NOTE_AS6,  NOTE_F6,  NOTE_G6,  NOTE_GS6, NOTE_F6,  NOTE_F6, NOTE_G6, NOTE_GS6, NOTE_F6,  NOTE_GS6,  NOTE_D7, NOTE_C7, NOTE_AS6,   NOTE_D7,  NOTE_DS7};int duration[] = {      6,       8,         2.5,        8,       4,         2,        6,        10,        4,        3,       8,       4,       4,        6,       8,         4,       4,        6,       8,       2.5,       6,         8,        8,       8,        4,         4,         2};
    int sober[]={NOTE_D4,  NOTE_G4, NOTE_B4, NOTE_G4};int duration3[] ={2,         3,       3,       2};
    int buzzed[]={NOTE_DS4,  NOTE_FS4, NOTE_C5, NOTE_B4};int duration4[] ={2,         3,       3,       2};
    int high[]={NOTE_G4,  NOTE_B4, NOTE_C5, NOTE_B4};int duration5[] ={2,         3,       3,       2};
    int stoned[]={NOTE_DS2,  NOTE_DS2,  NOTE_DS2,  NOTE_DS2,  NOTE_DS2, NOTE_DS2 };int duration6[] ={2,         2,       16,          16,        16,             2};
    int ripped[]={NOTE_G4,  NOTE_A4,  NOTE_B4,  NOTE_B4, NOTE_G4,  NOTE_A4,  NOTE_B4,  NOTE_B4, NOTE_FS4, NOTE_E4, NOTE_DS4, NOTE_B4, NOTE_B4, NOTE_C5,  NOTE_B4, NOTE_B4, NOTE_A4, NOTE_A4, NOTE_B4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_AS4, NOTE_G4 };int duration7[] ={7,         8,       8,          1,     7,         8,       8,          4,        4,       8,       1,        16,        16,       4,        8,       16,       8,      16,       1,       8,       8,       8,        4,       2 };
    int melody2[] = { NOTE_DS4 };int duration2[] = {0};
    
    void setup() {
    Serial.begin(9600);        // calibrate during the first five seconds     while (millis() < 5000) {    sensorValue = analogRead(sensorPin);    sensorMin =sensorValue/4;    if (sensorMin*7>=1024){      sensorMax=sensorValue+20;     }    else {    sensorMax = sensorMin*7;     }     Serial.println(sensorMax);    }
    }
    
    void loop() {      // read the sensor:    sensorValue = analogRead(sensorPin);
    // apply the calibration to the sensor reading    sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 5);
    // in case the sensor value is outside the range seen during calibration    sensorValue = constrain(sensorValue, 0, 6);       //start testing the range//      switch (sensorValue) {    case 0:    // your hand is on the sensor    Serial.println("sober");
    time=0;    for (int thisNote3 = 0; thisNote3 < 4; thisNote3++) {        int noteDuration3 = 1000/duration3[thisNote3];        tone(8, sober[thisNote3],noteDuration3);        int pauseBetweenNotes3 = noteDuration3 * 3;        delay(pauseBetweenNotes3);        noTone(8);
    }       break;              case 1:    // your hand is close to the sensor    Serial.println("buzzed");    time=0;    for (int thisNote4 = 0; thisNote4 < 4; thisNote4++) {        int noteDuration4 = 1000/duration4[thisNote4];        tone(8, buzzed[thisNote4],noteDuration4);        int pauseBetweenNotes4 = noteDuration4* 3;        delay(pauseBetweenNotes4);        noTone(8);
    }      break;       case 2:    // your hand is a few inches from the sensor    Serial.println("high");    time=0;    for (int thisNote5 = 0; thisNote5 < 4; thisNote5++) {        int noteDuration5 = 1000/duration5[thisNote5];        tone(8, high[thisNote5],noteDuration5);        int pauseBetweenNotes5 = noteDuration5* 3;        delay(pauseBetweenNotes5);        noTone(8);
    }       break;        case 3:    // your hand is nowhere near the sensor    Serial.println("stoned");    time=0;    for (int thisNote6 = 0; thisNote6 < 6; thisNote6++) {        int noteDuration6 = 1000/duration6[thisNote6];        tone(8, stoned[thisNote6],noteDuration6);        int pauseBetweenNotes6 = noteDuration6* 3;        delay(pauseBetweenNotes6);        noTone(8);
    }       break;
    case 4:    // medium light    Serial.println("ripped");    time=0;    for (int thisNote7 = 0; thisNote7<24; thisNote7++) {        int noteDuration7 = 1000/duration7[thisNote7];        tone(8, ripped[thisNote7],noteDuration7);        int pauseBetweenNotes7 = noteDuration7* 3;        delay(pauseBetweenNotes7);        noTone(8);
    }    break;        case 5:// full on light    Serial.println("blitzed");    Serial.println(time);    time++;
    for (int thisNote = 0; thisNote < 27; thisNote++) {      if (time < 2){        // to calculate the note duration, take one second         // divided by the note type.        //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.        int noteDuration = 1000/duration[thisNote];        tone(8, lullaby[thisNote],noteDuration);        // to distinguish the notes, set a minimum time between them.        // the note's duration + 30% seems to work well:        int pauseBetweenNotes = noteDuration * 2;        delay(pauseBetweenNotes);        // stop the tone playing:        //     noTone(8);      }      else {        for (int thisNote2 = 0; thisNote2 < 4; thisNote2++){          int noteDuration2 = 1000/duration2[thisNote2];          tone(8, melody2[thisNote2], noteDuration2);
    int pauseBetweenNotes2 = noteDuration2 * 2;          delay(pauseBetweenNotes2);
    }      }
    }
    break;  }
    }
    
    #define NOTE_B0  31
    
    #define NOTE_C1  33
    
    #define NOTE_CS1 35
    
    #define NOTE_D1  37
    
    #define NOTE_DS1 39
    
    #define NOTE_E1  41
    
    #define NOTE_F1  44
    
    #define NOTE_FS1 46
    
    #define NOTE_G1  49
    
    #define NOTE_GS1 52
    
    #define NOTE_A1  55
    
    #define NOTE_AS1 58
    
    #define NOTE_B1  62
    
    #define NOTE_C2  65
    
    #define NOTE_CS2 69
    
    #define NOTE_D2  73
    
    #define NOTE_DS2 78
    
    #define NOTE_E2  82
    
    #define NOTE_F2  87
    
    #define NOTE_FS2 93
    
    #define NOTE_G2  98
    
    #define NOTE_GS2 104
    
    #define NOTE_A2  110
    
    #define NOTE_AS2 117
    
    #define NOTE_B2  123
    
    #define NOTE_C3  131
    
    #define NOTE_CS3 139
    
    #define NOTE_D3  147
    
    #define NOTE_DS3 156
    
    #define NOTE_E3  165
    
    #define NOTE_F3  175
    
    #define NOTE_FS3 185
    
    #define NOTE_G3  196
    
    #define NOTE_GS3 208
    
    #define NOTE_A3  220
    
    #define NOTE_AS3 233
    
    #define NOTE_B3  247
    
    #define NOTE_C4  262
    
    #define NOTE_CS4 277
    
    #define NOTE_D4  294
    
    #define NOTE_DS4 311
    
    #define NOTE_E4  330
    
    #define NOTE_F4  349
    
    #define NOTE_FS4 370
    
    #define NOTE_G4  392
    
    #define NOTE_GS4 415
    
    #define NOTE_A4  440
    
    #define NOTE_AS4 466
    
    #define NOTE_B4  494
    
    #define NOTE_C5  523
    
    #define NOTE_CS5 554
    
    #define NOTE_D5  587
    
    #define NOTE_DS5 622
    
    #define NOTE_E5  659
    
    #define NOTE_F5  698
    
    #define NOTE_FS5 740
    
    #define NOTE_G5  784
    
    #define NOTE_GS5 831
    
    #define NOTE_A5  880
    
    #define NOTE_AS5 932
    
    #define NOTE_B5  988
    
    #define NOTE_C6  1047
    
    #define NOTE_CS6 1109
    
    #define NOTE_D6  1175
    
    #define NOTE_DS6 1245
    
    #define NOTE_E6  1319
    
    #define NOTE_F6  1397
    
    #define NOTE_FS6 1480
    
    #define NOTE_G6  1568
    
    #define NOTE_GS6 1661
    
    #define NOTE_A6  1760
    
    </code>
    
    #define NOTE_AS6 1865
    
    #define NOTE_B6  1976
    
    #define NOTE_C7  2093
    
    #define NOTE_CS7 2217
    
    #define NOTE_D7  2349
    
    #define NOTE_DS7 2489
    
    #define NOTE_E7  2637
    
    #define NOTE_F7  2794
    
    #define NOTE_FS7 2960
    
    #define NOTE_G7  3136
    
    #define NOTE_GS7 3322
    
    #define NOTE_A7  3520
    
    #define NOTE_AS7 3729
    
    #define NOTE_B7  3951
    
    #define NOTE_C8  4186
    
    #define NOTE_CS8 4435
    
    #define NOTE_D8  4699
    
    #define  R
    
    
    
     
  • Unknown's avatar

    hilalkoyuncu 11:27 pm on February 3, 2011 Permalink | Reply  

    Hilal’s talking robot, internal organs exposed 

    My arduino has this whole speech for you, click to listen.

    http://www.youtube.com/watch?v=3BFc1iQ1TqU

    Sounds/Codes:

    Pitch library that I created for ardu: hilal_pitch.h

    
    #define A0	9091
    #define A0S	8581
    #define B_0	8099
    #define C1	7644
    #define C1S	7216
    #define D1	6811
    #define D1S	6428
    #define E1	6068
    #define F1	5727
    #define F1S	5405
    #define G1	5102
    #define G1S	4816
    #define A1	4545
    #define A1S	4290
    #define B_1	4050
    #define C2	3822
    #define C2S	3608
    #define D2	3405
    #define D2S	3214
    #define E2	3034
    #define F2	2863
    #define F2S	2703
    #define G2	2551
    #define G2S	2408
    #define A2	2273
    #define A2S	2145
    #define B2	2025
    #define C3	1911
    #define C3S	1804
    #define D3	1703
    #define D3S	1607
    #define E3	1517
    #define F3	1432
    #define F3S	1351
    #define G3	1276
    #define G3S	1204
    #define A3	1136
    #define A3S	1073
    #define B3	1012
    #define C4	956
    #define C4S	902
    #define D4	851
    #define D4S	804
    #define E4	758
    #define F4	716
    #define F4S	676
    #define G4	638
    #define G4S	602
    #define A4	568
    #define A4S	536
    #define B4	506
    #define C5	478
    #define C5S	451
    #define D5	426
    #define D5S	402
    #define E5	379
    #define F5	358
    #define F5S	338
    #define G5	319
    #define G5S	301
    #define A5	284
    #define A5S	268
    #define B5	253
    #define C6	239
    #define C6S	225
    #define D6	213
    #define D6S	201
    #define E6	190
    #define F6	179
    #define F6S	169
    #define G6	159
    #define G6S	150
    #define A6	142
    #define A6S	134
    #define B6	127
    #define C7	119
    #define C7S	113
    #define D7	106
    #define D7S	100
    #define E7	95
    #define F7	89
    #define F7S	84
    #define G7	80
    #define G7S	75
    #define A7	71
    #define A7S	67
    #define B7	63
    #define C8	60
    #define  R     0
    
    

    Hello I’m on! :

     
    /* Play HelloImOn 
     * -----------
     *
     * Program to play a simple HelloImOn 
     *
     * Tones are created by quickly pulsing a speaker on and off 
     *   using PWM, to create signature frequencies.
     *
     * Each note has a frequency, created by varying the period of 
     *  vibration, measured in microseconds. We'll use pulse-width
     *  modulation (PWM) to create that vibration.
    
     * We calculate the pulse-width to be half the period; we pulse 
     *  the speaker HIGH for 'pulse-width' microseconds, then LOW 
     *  for 'pulse-width' microseconds.
     *  This pulsing creates a vibration of the desired frequency.
     *
     * (cleft) 2005 D. Cuartielles for K3
     * Refactoring and comments 2006 clay.shirky@nyu.edu
     * See NOTES in comments at end for possible improvements
     */
    
    // TONES  ==========================================
    // Start by defining the relationship between 
    //       note, period, &  frequency. 
    
    
    // SETUP ============================================
    
     #include "hilal_pitch.h"
     
    // Set up speaker on a PWM pin (digital 9, 10 or 11)
    int speakerOut = 9;
    // Do we want debugging on serial out? 1 for yes, 0 for no
    int DEBUG = 1;
    
    void setup() { 
      pinMode(speakerOut, OUTPUT);
      if (DEBUG) { 
        Serial.begin(9600); // Set serial out if we want debugging
      } 
    }
    
    // HelloImOn  and TIMING  =======================================
    //  HelloImOn [] is an array of notes, accompanied by beats[], 
    //  which sets each note's relative length (higher #, longer note) 
    
    int HelloImOn[] = { F2S, A2, D3, F3S, A3, D5S,  R };
    int beats[]  = { 8, 8, 8, 8, 8, 32, 16};
    int MAX_COUNT = sizeof(HelloImOn )/2; // HelloImOn  length, for looping.
    
    // Set overall tempo
    long tempo = 10000;
    // Set length of pause between notes
    int pause = 1000;
    // Loop variable to increase Rest length
    int rest_count = 110; //<-BLETCHEROUS HACK; See NOTES
    
    // Initialize core variables
    int ton = 0;
    int beat = 0;
    long duration  = 0;
    
    // PLAY TONE  ==============================================
    // Pulse the speaker to play a tone for a particular duration
    void playTone() {
      long elapsed_time = 0;
      if (ton > 0) { // if this isn't a Rest beat, while the tone has 
        //  played less long than 'duration', pulse speaker HIGH and LOW
        while (elapsed_time < duration) {
    
          digitalWrite(speakerOut,HIGH);
          delayMicroseconds(ton / 2);
    
          // DOWN
          digitalWrite(speakerOut, LOW);
          delayMicroseconds(ton / 2);
    
          // Keep track of how long we pulsed
          elapsed_time += (ton);
        } 
      }
      else { // Rest beat; loop times delay
        for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
          delayMicroseconds(duration);  
        }                                
      }                                 
    }
    
    // LET THE WILD RUMPUS BEGIN =============================
    void loop() {
      // Set up a counter to pull from HelloImOn [] and beats[]
      for (int i=0; i<MAX_COUNT; i++) {
        ton = HelloImOn [i];
        beat = beats[i];
    
        duration = beat * tempo; // Set up timing
    
        playTone(); 
        // A pause between notes...
        delayMicroseconds(pause);
    
        if (DEBUG) { // If debugging, report loop, tone, beat, and duration
          Serial.print(i);
          Serial.print(":");
          Serial.print(beat);
          Serial.print(" ");    
          Serial.print(ton);
          Serial.print(" ");
          Serial.println(duration);
        }
      }
    }
    
    /*
     * NOTES
     * The program purports to hold a tone for 'duration' microseconds.
     *  Lies lies lies! It holds for at least 'duration' microseconds, _plus_
     *  any overhead created by incremeting elapsed_time (could be in excess of 
     *  3K microseconds) _plus_ overhead of looping and two digitalWrites()
     *  
     * As a result, a tone of 'duration' plays much more slowly than a rest
     *  of 'duration.' rest_count creates a loop variable to bring 'rest' beats 
     *  in line with 'tone' beats of the same length. 
     * 
     * rest_count will be affected by chip architecture and speed, as well as 
     *  overhead from any program mods. Past behavior is no guarantee of future 
     *  performance. Your mileage may vary. Light fuse and get away.
     *  
     * This could use a number of enhancements:
     * ADD code to let the programmer specify how many times the HelloImOn  should
     *     loop before stopping
     * ADD another octave
     * MOVE tempo, pause, and rest_count to #define statements
     * RE-WRITE to include volume, using analogWrite, as with the second program at
     *          http://www.arduino.cc/en/Tutorial/PlayHelloImOn 
     * ADD code to make the tempo settable by pot or other input device
     * ADD code to take tempo or volume settable by serial communication 
     *          (Requires 0005 or higher.)
     * ADD code to create a tone offset (higer or lower) through pot etc
     * REPLACE random HelloImOn  with opening bars to 'Smoke on the Water'
     */
    
    
    
    

    Yes!:

     
    /* Play Yes
     * -----------
     *
     * Program to play a simple Yes
     *
     * Tones are created by quickly pulsing a speaker on and off 
     *   using PWM, to create signature frequencies.
     *
     * Each note has a frequency, created by varying the period of 
     *  vibration, measured in microseconds. We'll use pulse-width
     *  modulation (PWM) to create that vibration.
    
     * We calculate the pulse-width to be half the period; we pulse 
     *  the speaker HIGH for 'pulse-width' microseconds, then LOW 
     *  for 'pulse-width' microseconds.
     *  This pulsing creates a vibration of the desired frequency.
     *
     * (cleft) 2005 D. Cuartielles for K3
     * Refactoring and comments 2006 clay.shirky@nyu.edu
     * See NOTES in comments at end for possible improvements
     */
    
    // TONES  ==========================================
    // Start by defining the relationship between 
    //       note, period, &  frequency. 
    
     #include "hilal_pitch.h"
     
    // SETUP ============================================
    // Set up speaker on a PWM pin (digital 9, 10 or 11)
    int speakerOut = 9;
    // Do we want debugging on serial out? 1 for yes, 0 for no
    int DEBUG = 1;
    
    void setup() { 
      pinMode(speakerOut, OUTPUT);
      if (DEBUG) { 
        Serial.begin(9600); // Set serial out if we want debugging
      } 
    }
    
    // Yes and TIMING  =======================================
    //  Yes[] is an array of notes, accompanied by beats[], 
    //  which sets each note's relative length (higher #, longer note) 
     
    int Yes[] = {F3S,F3S,R };
    int beats[]  = { 8,8, 16};
    int MAX_COUNT = sizeof(Yes)/2; // Yes length, for looping.
    
    // Set overall tempo
    long tempo = 10000;
    // Set length of pause between notes
    int pause = 1000;
    // Loop variable to increase Rest length
    int rest_count = 110; //<-BLETCHEROUS HACK; See NOTES
    
    // Initialize core variables
    int ton = 0;
    int beat = 0;
    long duration  = 0;
    
    // PLAY TONE  ==============================================
    // Pulse the speaker to play a tone for a particular duration
    void playTone() {
      long elapsed_time = 0;
      if (ton > 0) { // if this isn't a Rest beat, while the tone has 
        //  played less long than 'duration', pulse speaker HIGH and LOW
        while (elapsed_time < duration) {
    
          digitalWrite(speakerOut,HIGH);
          delayMicroseconds(ton / 2);
    
          // DOWN
          digitalWrite(speakerOut, LOW);
          delayMicroseconds(ton / 2);
    
          // Keep track of how long we pulsed
          elapsed_time += (ton);
        } 
      }
      else { // Rest beat; loop times delay
        for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
          delayMicroseconds(duration);  
        }                                
      }                                 
    }
    
    // LET THE WILD RUMPUS BEGIN =============================
    void loop() {
      // Set up a counter to pull from Yes[] and beats[]
      for (int i=0; i<MAX_COUNT; i++) {
        ton = Yes[i];
        beat = beats[i];
    
        duration = beat * tempo; // Set up timing
    
        playTone(); 
        // A pause between notes...
        delayMicroseconds(pause);
    
        if (DEBUG) { // If debugging, report loop, tone, beat, and duration
          Serial.print(i);
          Serial.print(":");
          Serial.print(beat);
          Serial.print(" ");    
          Serial.print(ton);
          Serial.print(" ");
          Serial.println(duration);
        }
      }
    }
    
    /*
     * NOTES
     * The program purports to hold a tone for 'duration' microseconds.
     *  Lies lies lies! It holds for at least 'duration' microseconds, _plus_
     *  any overhead created by incremeting elapsed_time (could be in excess of 
     *  3K microseconds) _plus_ overhead of looping and two digitalWrites()
     *  
     * As a result, a tone of 'duration' plays much more slowly than a rest
     *  of 'duration.' rest_count creates a loop variable to bring 'rest' beats 
     *  in line with 'tone' beats of the same length. 
     * 
     * rest_count will be affected by chip architecture and speed, as well as 
     *  overhead from any program mods. Past behavior is no guarantee of future 
     *  performance. Your mileage may vary. Light fuse and get away.
     *  
     * This could use a number of enhancements:
     * ADD code to let the programmer specify how many times the Yes should
     *     loop before stopping
     * ADD another octave
     * MOVE tempo, pause, and rest_count to #define statements
     * RE-WRITE to include volume, using analogWrite, as with the second program at
     *          http://www.arduino.cc/en/Tutorial/PlayYes
     * ADD code to make the tempo settable by pot or other input device
     * ADD code to take tempo or volume settable by serial communication 
     *          (Requires 0005 or higher.)
     * ADD code to create a tone offset (higer or lower) through pot etc
     * REPLACE random Yes with opening bars to 'Smoke on the Water'
     */
    
    
    
    

    I’m growing!!!:

     
    /* Play ImGrowing
     * -----------
     *
     * Program to play a simple ImGrowing
     *
     * Tones are created by quickly pulsing a speaker on and off 
     *   using PWM, to create signature frequencies.
     *
     * Each note has a frequency, created by varying the period of 
     *  vibration, measured in microseconds. We'll use pulse-width
     *  modulation (PWM) to create that vibration.
    
     * We calculate the pulse-width to be half the period; we pulse 
     *  the speaker HIGH for 'pulse-width' microseconds, then LOW 
     *  for 'pulse-width' microseconds.
     *  This pulsing creates a vibration of the desired frequency.
     *
     * (cleft) 2005 D. Cuartielles for K3
     * Refactoring and comments 2006 clay.shirky@nyu.edu
     * See NOTES in comments at end for possible improvements
     */
    
    // TONES  ==========================================
    // Start by defining the relationship between 
    //       note, period, &  frequency. 
    
    
    // Define a special note, 'R', to represent a rest
    
    
    
    
    // SETUP ============================================
    
    #include "hilal_pitch.h"
    
    // Set up speaker on a PWM pin (digital 9, 10 or 11)
    
    
    "
    
    int speakerOut = 9;
    // Do we want debugging on serial out? 1 for yes, 0 for no
    int DEBUG = 1;
    
    void setup() { 
      pinMode(speakerOut, OUTPUT);
      if (DEBUG) { 
        Serial.begin(9600); // Set serial out if we want debugging
      } 
    }
    
    // ImGrowing and TIMING  =======================================
    //  ImGrowing[] is an array of notes, accompanied by beats[], 
    //  which sets each note's relative length (higher #, longer note) 
     
    int ImGrowing[] = {C3,D3,E3,F3,G3,A3,B3,C4,D4,E4,F4,G4,A4,B4,C5S, R };
    int beats[]  = {4,4,4,4,4,4,4,4,4,4,4,4,4,4,24,8};
    int MAX_COUNT = sizeof(ImGrowing)/2; // ImGrowing length, for looping.
    
    // Set overall tempo
    long tempo = 10000;
    // Set length of pause between notes
    int pause = 1000;
    // Loop variable to increase Rest length
    int rest_count = 110; //<-BLETCHEROUS HACK; See NOTES
    
    // Initialize core variables
    int ton = 0;
    int beat = 0;
    long duration  = 0;
    
    // PLAY TONE  ==============================================
    // Pulse the speaker to play a tone for a particular duration
    void playTone() {
      long elapsed_time = 0;
      if (ton > 0) { // if this isn't a Rest beat, while the tone has 
        //  played less long than 'duration', pulse speaker HIGH and LOW
        while (elapsed_time < duration) {
    
          digitalWrite(speakerOut,HIGH);
          delayMicroseconds(ton / 2);
    
          // DOWN
          digitalWrite(speakerOut, LOW);
          delayMicroseconds(ton / 2);
    
          // Keep track of how long we pulsed
          elapsed_time += (ton);
        } 
      }
      else { // Rest beat; loop times delay
        for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
          delayMicroseconds(duration);  
        }                                
      }                                 
    }
    
    // LET THE WILD RUMPUS BEGIN =============================
    void loop() {
      // Set up a counter to pull from ImGrowing[] and beats[]
      for (int i=0; i<MAX_COUNT; i++) {
        ton = ImGrowing[i];
        beat = beats[i];
    
        duration = beat * tempo; // Set up timing
    
        playTone(); 
        // A pause between notes...
        delayMicroseconds(pause);
    
        if (DEBUG) { // If debugging, report loop, tone, beat, and duration
          Serial.print(i);
          Serial.print(":");
          Serial.print(beat);
          Serial.print(" ");    
          Serial.print(ton);
          Serial.print(" ");
          Serial.println(duration);
        }
      }
    }
    
    /*
     * NOTES
     * The program purports to hold a tone for 'duration' microseconds.
     *  Lies lies lies! It holds for at least 'duration' microseconds, _plus_
     *  any overhead created by incremeting elapsed_time (could be in excess of 
     *  3K microseconds) _plus_ overhead of looping and two digitalWrites()
     *  
     * As a result, a tone of 'duration' plays much more slowly than a rest
     *  of 'duration.' rest_count creates a loop variable to bring 'rest' beats 
     *  in line with 'tone' beats of the same length. 
     * 
     * rest_count will be affected by chip architecture and speed, as well as 
     *  overhead from any program mods. Past behavior is no guarantee of future 
     *  performance. Your mileage may vary. Light fuse and get away.
     *  
     * This could use a number of enhancements:
     * ADD code to let the programmer specify how many times the ImGrowing should
     *     loop before stopping
     * ADD another octave
     * MOVE tempo, pause, and rest_count to #define statements
     * RE-WRITE to include volume, using analogWrite, as with the second program at
     *          http://www.arduino.cc/en/Tutorial/PlayImGrowing
     * ADD code to make the tempo settable by pot or other input device
     * ADD code to take tempo or volume settable by serial communication 
     *          (Requires 0005 or higher.)
     * ADD code to create a tone offset (higer or lower) through pot etc
     * REPLACE random ImGrowing with opening bars to 'Smoke on the Water'
     */
    
    
    
    

    I’m happy:

    
    
    // Define a special note, 'R', to represent a rest
    
    
    // SETUP ============================================
    
     #include "hilal_pitch.h"
     
    // Set up speaker on a PWM pin (digital 9, 10 or 11)
    int speakerOut = 9;
    // Do we want debugging on serial out? 1 for yes, 0 for no
    int DEBUG = 1;
    
    void setup() { 
      pinMode(speakerOut, OUTPUT);
      if (DEBUG) { 
        Serial.begin(9600); // Set serial out if we want debugging
      } 
    }
    
    // ImHappy and TIMING  =======================================
    //  ImHappy[] is an array of notes, accompanied by beats[], 
    //  which sets each note's relative length (higher #, longer note) 
     
    int ImHappy[] = {C3S,R, C3S,F3S,R };
    int beats[]  = { 16, 2, 8, 64, 32 };
    int MAX_COUNT = sizeof(ImHappy)/2; // ImHappy length, for looping.
    
    // Set overall tempo
    long tempo = 10000;
    // Set length of pause between notes
    int pause = 1000;
    // Loop variable to increase Rest length
    int rest_count = 110; //<-BLETCHEROUS HACK; See NOTES
    
    // Initialize core variables
    int ton = 0;
    int beat = 0;
    long duration  = 0;
    
    // PLAY TONE  ==============================================
    // Pulse the speaker to play a tone for a particular duration
    void playTone() {
      long elapsed_time = 0;
      if (ton > 0) { // if this isn't a Rest beat, while the tone has 
        //  played less long than 'duration', pulse speaker HIGH and LOW
        while (elapsed_time < duration) {
    
          digitalWrite(speakerOut,HIGH);
          delayMicroseconds(ton / 2);
    
          // DOWN
          digitalWrite(speakerOut, LOW);
          delayMicroseconds(ton / 2);
    
          // Keep track of how long we pulsed
          elapsed_time += (ton);
        } 
      }
      else { // Rest beat; loop times delay
        for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
          delayMicroseconds(duration);  
        }                                
      }                                 
    }
    
    // LET THE WILD RUMPUS BEGIN =============================
    void loop() {
      // Set up a counter to pull from ImHappy[] and beats[]
      for (int i=0; i<MAX_COUNT; i++) {
        ton = ImHappy[i];
        beat = beats[i];
    
        duration = beat * tempo; // Set up timing
    
        playTone(); 
        // A pause between notes...
        delayMicroseconds(pause);
    
        if (DEBUG) { // If debugging, report loop, tone, beat, and duration
          Serial.print(i);
          Serial.print(":");
          Serial.print(beat);
          Serial.print(" ");    
          Serial.print(ton);
          Serial.print(" ");
          Serial.println(duration);
        }
      }
    }
    
    /*
     * NOTES
     * The program purports to hold a tone for 'duration' microseconds.
     *  Lies lies lies! It holds for at least 'duration' microseconds, _plus_
     *  any overhead created by incremeting elapsed_time (could be in excess of 
     *  3K microseconds) _plus_ overhead of looping and two digitalWrites()
     *  
     * As a result, a tone of 'duration' plays much more slowly than a rest
     *  of 'duration.' rest_count creates a loop variable to bring 'rest' beats 
     *  in line with 'tone' beats of the same length. 
     * 
     * rest_count will be affected by chip architecture and speed, as well as 
     *  overhead from any program mods. Past behavior is no guarantee of future 
     *  performance. Your mileage may vary. Light fuse and get away.
     *  
     * This could use a number of enhancements:
     * ADD code to let the programmer specify how many times the ImHappy should
     *     loop before stopping
     * ADD another octave
     * MOVE tempo, pause, and rest_count to #define statements
     * RE-WRITE to include volume, using analogWrite, as with the second program at
     *          http://www.arduino.cc/en/Tutorial/PlayImHappy
     * ADD code to make the tempo settable by pot or other input device
     * ADD code to take tempo or volume settable by serial communication 
     *          (Requires 0005 or higher.)
     * ADD code to create a tone offset (higer or lower) through pot etc
     * REPLACE random ImHappy with opening bars to 'Smoke on the Water'
     */
    
    
    
    

    No!!!:

     
    /* Play No
     * -----------
     *
     * Program to play a simple No
     *
     * Tones are created by quickly pulsing a speaker on and off 
     *   using PWM, to create signature frequencies.
     *
     * Each note has a frequency, created by varying the period of 
     *  vibration, measured in microseconds. We'll use pulse-width
     *  modulation (PWM) to create that vibration.
    
     * We calculate the pulse-width to be half the period; we pulse 
     *  the speaker HIGH for 'pulse-width' microseconds, then LOW 
     *  for 'pulse-width' microseconds.
     *  This pulsing creates a vibration of the desired frequency.
     *
     * (cleft) 2005 D. Cuartielles for K3
     * Refactoring and comments 2006 clay.shirky@nyu.edu
     * See NOTES in comments at end for possible improvements
     */
    
    // TONES  ==========================================
    // Start by defining the relationship between 
    //       note, period, &  frequency. 
    
     #include "hilal_pitch.h"
    
    // SETUP ============================================
    // Set up speaker on a PWM pin (digital 9, 10 or 11)
    int speakerOut = 9;
    // Do we want debugging on serial out? 1 for No, 0 for no
    int DEBUG = 1;
    
    void setup() { 
      pinMode(speakerOut, OUTPUT);
      if (DEBUG) { 
        Serial.begin(9600); // Set serial out if we want debugging
      } 
    }
    
    // No and TIMING  =======================================
    //  No[] is an array of notes, accompanied by beats[], 
    //  which sets each note's relative length (higher #, longer note) 
     
    int No[] = {C1S, R };
    int beats[]  = { 64, 16};
    int MAX_COUNT = sizeof(No)/2; // No length, for looping.
    
    // Set overall tempo
    long tempo = 10000;
    // Set length of pause between notes
    int pause = 1000;
    // Loop variable to increase Rest length
    int rest_count = 110; //<-BLETCHEROUS HACK; See NOTES
    
    // Initialize core variables
    int ton = 0;
    int beat = 0;
    long duration  = 0;
    
    // PLAY TONE  ==============================================
    // Pulse the speaker to play a tone for a particular duration
    void playTone() {
      long elapsed_time = 0;
      if (ton > 0) { // if this isn't a Rest beat, while the tone has 
        //  played less long than 'duration', pulse speaker HIGH and LOW
        while (elapsed_time < duration) {
    
          digitalWrite(speakerOut,HIGH);
          delayMicroseconds(ton / 2);
    
          // DOWN
          digitalWrite(speakerOut, LOW);
          delayMicroseconds(ton / 2);
    
          // Keep track of how long we pulsed
          elapsed_time += (ton);
        } 
      }
      else { // Rest beat; loop times delay
        for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
          delayMicroseconds(duration);  
        }                                
      }                                 
    }
    
    // LET THE WILD RUMPUS BEGIN =============================
    void loop() {
      // Set up a counter to pull from No[] and beats[]
      for (int i=0; i<MAX_COUNT; i++) {
        ton = No[i];
        beat = beats[i];
    
        duration = beat * tempo; // Set up timing
    
        playTone(); 
        // A pause between notes...
        delayMicroseconds(pause);
    
        if (DEBUG) { // If debugging, report loop, tone, beat, and duration
          Serial.print(i);
          Serial.print(":");
          Serial.print(beat);
          Serial.print(" ");    
          Serial.print(ton);
          Serial.print(" ");
          Serial.println(duration);
        }
      }
    }
    
    /*
     * NOTES
     * The program purports to hold a tone for 'duration' microseconds.
     *  Lies lies lies! It holds for at least 'duration' microseconds, _plus_
     *  any overhead created by incremeting elapsed_time (could be in excess of 
     *  3K microseconds) _plus_ overhead of looping and two digitalWrites()
     *  
     * As a result, a tone of 'duration' plays much more slowly than a rest
     *  of 'duration.' rest_count creates a loop variable to bring 'rest' beats 
     *  in line with 'tone' beats of the same length. 
     * 
     * rest_count will be affected by chip architecture and speed, as well as 
     *  overhead from any program mods. Past behavior is no guarantee of future 
     *  performance. Your mileage may vary. Light fuse and get away.
     *  
     * This could use a number of enhancements:
     * ADD code to let the programmer specify how many times the No should
     *     loop before stopping
     * ADD another octave
     * MOVE tempo, pause, and rest_count to #define statements
     * RE-WRITE to include volume, using analogWrite, as with the second program at
     *          http://www.arduino.cc/en/Tutorial/PlayNo
     * ADD code to make the tempo settable by pot or other input device
     * ADD code to take tempo or volume settable by serial communication 
     *          (Requires 0005 or higher.)
     * ADD code to create a tone offset (higer or lower) through pot etc
     * REPLACE random No with opening bars to 'Smoke on the Water'
     */
    
    
    
    

    Help!!I’m running out of battery:

     
    /* Play Help
     * -----------
     *
     * Program to play a simple Help
     *
     * Tones are created by quickly pulsing a speaker on and off 
     *   using PWM, to create signature frequencies.
     *
     * Each Helpte has a frequency, created by varying the period of 
     *  vibration, measured in microseconds. We'll use pulse-width
     *  modulation (PWM) to create that vibration.
    
     * We calculate the pulse-width to be half the period; we pulse 
     *  the speaker HIGH for 'pulse-width' microseconds, then LOW 
     *  for 'pulse-width' microseconds.
     *  This pulsing creates a vibration of the desired frequency.
     *
     * (cleft) 2005 D. Cuartielles for K3
     * Refactoring and comments 2006 clay.shirky@nyu.edu
     * See HelpTES in comments at end for possible improvements
     */
    
    // TONES  ==========================================
    // Start by defining the relationship between 
    //       Helpte, period, &  frequency. 
    
    
    // SETUP ============================================
    
     #include "hilal_pitch.h"
     
    // Set up speaker on a PWM pin (digital 9, 10 or 11)
    int speakerOut = 9;
    // Do we want debugging on serial out? 1 for Help, 0 for Help
    int DEBUG = 1;
    
    void setup() { 
      pinMode(speakerOut, OUTPUT);
      if (DEBUG) { 
        Serial.begin(9600); // Set serial out if we want debugging
      } 
    }
    
    // Help and TIMING  =======================================
    //  Help[] is an array of Helptes, accompanied by beats[], 
    //  which sets each Helpte's relative length (higher #, longer Helpte) 
     
    int Help[] = {C3,F2 };
    int beats[]  = { 7,7};
    int MAX_COUNT = sizeof(Help)/2; // Help length, for looping.
    
    // Set overall tempo
    long tempo = 10000;
    // Set length of pause between Helptes
    int pause = 1000;
    // Loop variable to increase Rest length
    int rest_count = 110; //<-BLETCHEROUS HACK; See HelpTES
    
    // Initialize core variables
    int ton = 0;
    int beat = 0;
    long duration  = 0;
    
    // PLAY TONE  ==============================================
    // Pulse the speaker to play a tone for a particular duration
    void playTone() {
      long elapsed_time = 0;
      if (ton > 0) { // if this isn't a Rest beat, while the tone has 
        //  played less long than 'duration', pulse speaker HIGH and LOW
        while (elapsed_time < duration) {
    
          digitalWrite(speakerOut,HIGH);
          delayMicroseconds(ton / 2);
    
          // DOWN
          digitalWrite(speakerOut, LOW);
          delayMicroseconds(ton / 2);
    
          // Keep track of how long we pulsed
          elapsed_time += (ton);
        } 
      }
      else { // Rest beat; loop times delay
        for (int j = 0; j < rest_count; j++) { // See HelpTE on rest_count
          delayMicroseconds(duration);  
        }                                
      }                                 
    }
    
    // LET THE WILD RUMPUS BEGIN =============================
    void loop() {
      // Set up a counter to pull from Help[] and beats[]
      for (int i=0; i<MAX_COUNT; i++) {
        ton = Help[i];
        beat = beats[i];
    
        duration = beat * tempo; // Set up timing
    
        playTone(); 
        // A pause between Helptes...
        delayMicroseconds(pause);
    
        if (DEBUG) { // If debugging, report loop, tone, beat, and duration
          Serial.print(i);
          Serial.print(":");
          Serial.print(beat);
          Serial.print(" ");    
          Serial.print(ton);
          Serial.print(" ");
          Serial.println(duration);
        }
      }
    }
    
    /*
     * HelpTES
     * The program purports to hold a tone for 'duration' microseconds.
     *  Lies lies lies! It holds for at least 'duration' microseconds, _plus_
     *  any overhead created by incremeting elapsed_time (could be in excess of 
     *  3K microseconds) _plus_ overhead of looping and two digitalWrites()
     *  
     * As a result, a tone of 'duration' plays much more slowly than a rest
     *  of 'duration.' rest_count creates a loop variable to bring 'rest' beats 
     *  in line with 'tone' beats of the same length. 
     * 
     * rest_count will be affected by chip architecture and speed, as well as 
     *  overhead from any program mods. Past behavior is Help guarantee of future 
     *  performance. Your mileage may vary. Light fuse and get away.
     *  
     * This could use a number of enhancements:
     * ADD code to let the programmer specify how many times the Help should
     *     loop before stopping
     * ADD aHelpther octave
     * MOVE tempo, pause, and rest_count to #define statements
     * RE-WRITE to include volume, using analogWrite, as with the second program at
     *          http://www.arduiHelp.cc/en/Tutorial/PlayHelp
     * ADD code to make the tempo settable by pot or other input device
     * ADD code to take tempo or volume settable by serial communication 
     *          (Requires 0005 or higher.)
     * ADD code to create a tone offset (higer or lower) through pot etc
     * REPLACE random Help with opening bars to 'Smoke on the Water'
     */
    
    
    
    

    I’m sad:

     
    /* Play ImSad
     * -----------
     *
     * Program to play a simple ImSad
     *
     * Tones are created by quickly pulsing a speaker on and off 
     *   using PWM, to create signature frequencies.
     *
     * Each ImSadte has a frequency, created by varying the period of 
     *  vibration, measured in microseconds. We'll use pulse-width
     *  modulation (PWM) to create that vibration.
    
     * We calculate the pulse-width to be half the period; we pulse 
     *  the speaker HIGH for 'pulse-width' microseconds, then LOW 
     *  for 'pulse-width' microseconds.
     *  This pulsing creates a vibration of the desired frequency.
     *
     * (cleft) 2005 D. Cuartielles for K3
     * Refactoring and comments 2006 clay.shirky@nyu.edu
     * See ImSadTES in comments at end for possible improvements
     */
    
    // TONES  ==========================================
    // Start by defining the relationship between 
    //       ImSadte, period, &  frequency. 
    
    // Define a special ImSadte, 'R', to represent a rest
    
    
    // SETUP ============================================
    
     #include "hilal_pitch.h"
     
    // Set up speaker on a PWM pin (digital 9, 10 or 11)
    
    int speakerOut = 9;
    // Do we want debugging on serial out? 1 for ImSad, 0 for ImSad
    int DEBUG = 1;
    
    void setup() { 
      pinMode(speakerOut, OUTPUT);
      if (DEBUG) { 
        Serial.begin(9600); // Set serial out if we want debugging
      } 
    }
    
    // ImSad and TIMING  =======================================
    //  ImSad[] is an array of ImSadtes, accompanied by beats[], 
    //  which sets each ImSadte's relative length (higher #, longer ImSadte) 
     
    int ImSad[] = {F2, F2S,C3S, C2S, R };
    int beats[]  = { 32,32,32,80, 16};
    int MAX_COUNT = sizeof(ImSad)/2; // ImSad length, for looping.
    
    // Set overall tempo
    long tempo = 10000;
    // Set length of pause between ImSadtes
    int pause = 1000;
    // Loop variable to increase Rest length
    int rest_count = 110; //<-BLETCHEROUS HACK; See ImSadTES
    
    // Initialize core variables
    int ton = 0;
    int beat = 0;
    long duration  = 0;
    
    // PLAY TONE  ==============================================
    // Pulse the speaker to play a tone for a particular duration
    void playTone() {
      long elapsed_time = 0;
      if (ton > 0) { // if this isn't a Rest beat, while the tone has 
        //  played less long than 'duration', pulse speaker HIGH and LOW
        while (elapsed_time < duration) {
    
          digitalWrite(speakerOut,HIGH);
          delayMicroseconds(ton / 2);
    
          // DOWN
          digitalWrite(speakerOut, LOW);
          delayMicroseconds(ton / 2);
    
          // Keep track of how long we pulsed
          elapsed_time += (ton);
        } 
      }
      else { // Rest beat; loop times delay
        for (int j = 0; j < rest_count; j++) { // See ImSadTE on rest_count
          delayMicroseconds(duration);  
        }                                
      }                                 
    }
    
    // LET THE WILD RUMPUS BEGIN =============================
    void loop() {
      // Set up a counter to pull from ImSad[] and beats[]
      for (int i=0; i<MAX_COUNT; i++) {
        ton = ImSad[i];
        beat = beats[i];
    
        duration = beat * tempo; // Set up timing
    
        playTone(); 
        // A pause between ImSadtes...
        delayMicroseconds(pause);
    
        if (DEBUG) { // If debugging, report loop, tone, beat, and duration
          Serial.print(i);
          Serial.print(":");
          Serial.print(beat);
          Serial.print(" ");    
          Serial.print(ton);
          Serial.print(" ");
          Serial.println(duration);
        }
      }
    }
    
    /*
     * ImSadTES
     * The program purports to hold a tone for 'duration' microseconds.
     *  Lies lies lies! It holds for at least 'duration' microseconds, _plus_
     *  any overhead created by incremeting elapsed_time (could be in excess of 
     *  3K microseconds) _plus_ overhead of looping and two digitalWrites()
     *  
     * As a result, a tone of 'duration' plays much more slowly than a rest
     *  of 'duration.' rest_count creates a loop variable to bring 'rest' beats 
     *  in line with 'tone' beats of the same length. 
     * 
     * rest_count will be affected by chip architecture and speed, as well as 
     *  overhead from any program mods. Past behavior is ImSad guarantee of future 
     *  performance. Your mileage may vary. Light fuse and get away.
     *  
     * This could use a number of enhancements:
     * ADD code to let the programmer specify how many times the ImSad should
     *     loop before stopping
     * ADD aImSadther octave
     * MOVE tempo, pause, and rest_count to #define statements
     * RE-WRITE to include volume, using analogWrite, as with the second program at
     *          http://www.arduiImSad.cc/en/Tutorial/PlayImSad
     * ADD code to make the tempo settable by pot or other input device
     * ADD code to take tempo or volume settable by serial communication 
     *          (Requires 0005 or higher.)
     * ADD code to create a tone offset (higer or lower) through pot etc
     * REPLACE random ImSad with opening bars to 'Smoke on the Water'
     */
    
    
    

    Bye I’m off. :

     
    /* Play ByeImOff
     * -----------
     *
     * Program to play a simple ByeImOff
     *
     * Tones are created by quickly pulsing a speaker on and off 
     *   using PWM, to create signature frequencies.
     *
     * Each note has a frequency, created by varying the period of 
     *  vibration, measured in microseconds. We'll use pulse-width
     *  modulation (PWM) to create that vibration.
    
     * We calculate the pulse-width to be half the period; we pulse 
     *  the speaker HIGH for 'pulse-width' microseconds, then LOW 
     *  for 'pulse-width' microseconds.
     *  This pulsing creates a vibration of the desired frequency.
     *
     * (cleft) 2005 D. Cuartielles for K3
     * Refactoring and comments 2006 clay.shirky@nyu.edu
     * See NOTES in comments at end for possible improvements
     */
    
    // TONES  ==========================================
    // Start by defining the relationship between 
    //       note, period, &  frequency. 
    
    
    // Define a special note, 'R', to represent a rest
    
    // SETUP ============================================
    
    #include "hilal_pitch.h"
    
    // Set up speaker on a PWM pin (digital 9, 10 or 11)
    int speakerOut = 9;
    // Do we want debugging on serial out? 1 for yes, 0 for no
    int DEBUG = 1;
    
    void setup() { 
      pinMode(speakerOut, OUTPUT);
      if (DEBUG) { 
        Serial.begin(9600); // Set serial out if we want debugging
      } 
    }
    
    // ByeImOff and TIMING  =======================================
    //  ByeImOff[] is an array of notes, accompanied by beats[], 
    //  which sets each note's relative length (higher #, longer note) 
     
    int ByeImOff[] = { D5S, A3, F3S, D3, A2, F2S, R };
    int beats[]  = { 8, 8, 8, 8,8, 32, 16};
    int MAX_COUNT = sizeof(ByeImOff)/2; // ByeImOff length, for looping.
    
    // Set overall tempo
    long tempo = 10000;
    // Set length of pause between notes
    int pause = 1000;
    // Loop variable to increase Rest length
    int rest_count = 110; //<-BLETCHEROUS HACK; See NOTES
    
    // Initialize core variables
    int ton = 0;
    int beat = 0;
    long duration  = 0;
    
    // PLAY TONE  ==============================================
    // Pulse the speaker to play a tone for a particular duration
    void playTone() {
      long elapsed_time = 0;
      if (ton > 0) { // if this isn't a Rest beat, while the tone has 
        //  played less long than 'duration', pulse speaker HIGH and LOW
        while (elapsed_time < duration) {
    
          digitalWrite(speakerOut,HIGH);
          delayMicroseconds(ton / 2);
    
          // DOWN
          digitalWrite(speakerOut, LOW);
          delayMicroseconds(ton / 2);
    
          // Keep track of how long we pulsed
          elapsed_time += (ton);
        } 
      }
      else { // Rest beat; loop times delay
        for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
          delayMicroseconds(duration);  
        }                                
      }                                 
    }
    
    // LET THE WILD RUMPUS BEGIN =============================
    void loop() {
      // Set up a counter to pull from ByeImOff[] and beats[]
      for (int i=0; i<MAX_COUNT; i++) {
        ton = ByeImOff[i];
        beat = beats[i];
    
        duration = beat * tempo; // Set up timing
    
        playTone(); 
        // A pause between notes...
        delayMicroseconds(pause);
    
        if (DEBUG) { // If debugging, report loop, tone, beat, and duration
          Serial.print(i);
          Serial.print(":");
          Serial.print(beat);
          Serial.print(" ");    
          Serial.print(ton);
          Serial.print(" ");
          Serial.println(duration);
        }
      }
    }
    
    /*
     * NOTES
     * The program purports to hold a tone for 'duration' microseconds.
     *  Lies lies lies! It holds for at least 'duration' microseconds, _plus_
     *  any overhead created by incremeting elapsed_time (could be in excess of 
     *  3K microseconds) _plus_ overhead of looping and two digitalWrites()
     *  
     * As a result, a tone of 'duration' plays much more slowly than a rest
     *  of 'duration.' rest_count creates a loop variable to bring 'rest' beats 
     *  in line with 'tone' beats of the same length. 
     * 
     * rest_count will be affected by chip architecture and speed, as well as 
     *  overhead from any program mods. Past behavior is no guarantee of future 
     *  performance. Your mileage may vary. Light fuse and get away.
     *  
     * This could use a number of enhancements:
     * ADD code to let the programmer specify how many times the ByeImOff should
     *     loop before stopping
     * ADD another octave
     * MOVE tempo, pause, and rest_count to #define statements
     * RE-WRITE to include volume, using analogWrite, as with the second program at
     *          http://www.arduino.cc/en/Tutorial/PlayByeImOff
     * ADD code to make the tempo settable by pot or other input device
     * ADD code to take tempo or volume settable by serial communication 
     *          (Requires 0005 or higher.)
     * ADD code to create a tone offset (higer or lower) through pot etc
     * REPLACE random ByeImOff with opening bars to 'Smoke on the Water'
     */
    
    
    
    

     

     
  • Unknown's avatar

    hilalkoyuncu 12:43 am on February 1, 2011 Permalink | Reply  

    Hi This is Hilal!!! 

    Hi my name is Hilal. I have studied cell bio and molecular genetics and worked as a researched assistant in a vascular biology research lab for two years.

    I am interested in this class because, I love physical computing and I want to learn more. I also love toys!

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel