Daniel TangParth ParulekarCyrus Cutter
Published

Project Musica

Our project teaches infants how to gauge distance, improving depth perception through the use of the song "My Heart Will Go On."

BeginnerShowcase (no instructions)5 hours535
Project Musica

Things used in this project

Story

Read more

Code

Music Code

C/C++
Code for "My Heart Will Go On"
int buzzerPin = 40;

// notes in the melody:
int melody[] = {
   NOTE_C4,NOTE_D4, NOTE_E4, NOTE_D4,NOTE_C4,NOTE_D4,
   NOTE_G4,NOTE_F4,NOTE_E4,NOTE_C4,NOTE_A3,NOTE_G3,
   NOTE_C4,NOTE_D4,NOTE_E4,NOTE_D4,NOTE_C4,NOTE_D4, NOTE_G4,NOTE_F4,
   NOTE_E4,NOTE_C4,NOTE_A3,NOTE_G3, /*intro-end*/ NOTE_C4,NOTE_C4,
   NOTE_C4, NOTE_C4, NOTE_B3, NOTE_C4, NOTE_C4, NOTE_B3, NOTE_C4, NOTE_D4,
   NOTE_E4, NOTE_D4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_B3, NOTE_C4, NOTE_C4, 
   NOTE_G3,/*chorus*/ NOTE_C4, NOTE_D4,NOTE_G3, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_E4,
   NOTE_F4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_B3, NOTE_C4, NOTE_C4, NOTE_B3, NOTE_C4, NOTE_D4,
   NOTE_E4, NOTE_D4, NOTE_C4};
   
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4 4, 1, 4,4,2,
  1, 4, 4, 1,1,1,
  4, 4, 1, 4,4,2,
  1, 4, 4, 1,1,1, /*intro end*/ 1, 4, 2, 2, 2, 1, 4, 2, 1, 2, 1, 1, 1, 4, 2, 2, 2, 1, 4, .5, /*chorus*/ .5, 1, 2, 1, 1, 4, 1, 1, 4, 1, 1, 4, 2, 1, 2, 2, 1, 2, 1, 1, .5};

UI, Implementation

C/C++
For running our program
/*
  Ultrasonic-Ranger to 4-digit-display
 Measure the distance to obstacles in front and display the value on 
 4-digital-display
 
 The circuit:
 * Ultrasonic Ranger attached to SPI plug on Grove Base BoosterPack
 * one side pin (either one) to ground
 * the other side pin to +VCC
 * LED anode (long leg) attached to RED_LED
 * LED cathode (short leg) attached to ground
 
 * Note:  
 
 
 This example code is in the public domain.
 
 http://www.seeedstudio.com/wiki/Grove_-_Ultrasonic_Ranger 
 */
 
#include "TM1637.h" 
#include "Ultrasonic.h"
/* Macro Define */
#define CLK               40                  /* 4-digital display clock pin */
#define DIO               39                 /* 4-digital display data pin */
#define BLINK_LED         RED_LED            /* blink led */
#define ULTRASONIC_PIN    38                  /* pin of the Ultrasonic Ranger */

/* Global Varibles */
TM1637 tm1637(CLK, DIO);                  /* 4-digital display object */
Ultrasonic ultrasonic(ULTRASONIC_PIN);    /* Ultrasonic Ranger object */
int distance = 0;                         /* varible to store the distance to obstacles in front */
int blink_interval = 0;                   /* led delay time */
int8_t bits[4] = {0};                     /* array to store the single bits of the value */

/* the setup() method runs once, when the sketch starts */
void setup() {
    
    /* Initialize 4-digital display */
    tm1637.init();
    tm1637.set(BRIGHT_TYPICAL);
  
    /* declare the red_led pin as an OUTPUT */
    pinMode(RED_LED, OUTPUT);
  
}

/* the loop() method runs over and over again */
void loop() {   
  
    distance = ultrasonic.MeasureInCentimeters();   /* read the value from the sensor */   
    
    memset(bits, 0, 4);                             /* reset array when we use it */
    for(int i = 3; i >= 0; i--) {
        /* get single bits of the analog value */
        bits[i] = distance % 10;
        distance = distance / 10;  
        tm1637.display(i, bits[i]);                 /* display by 4-digital display */
    }
    delay(100);
}

Credits

Daniel Tang
1 project • 0 followers
Contact
Parth Parulekar
2 projects • 0 followers
Contact
Cyrus Cutter
2 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.