SHUT THOSE BABIES UP!!!

These are very noisy sonographs! These babies are yet unborn. But they are sooo whiny, crying so loud. One likes darkness. One likes light. If they get what they want they calm down and purr, like good babies do. If they don’t, they cry so loud!

Arduino with photo resistor, 8 Ohm speakers, vibrating motor inside a plastic tub.

Download Code Here: lpimaging.net/parsons/comp2011/ArduinoBabiesCrying.zip

Light Loveing Code:

/*
  Based on Pitch follower
 */
 
int sensorReading;
int mapped;
int gap;
int note1 = 700;
int prevNote1=700;

void setup() {
  // initialize serial communications (for debugging only):
  Serial.begin(9600);
}

void loop() {
  // read the sensor:
  sensorReading = analogRead(A0);
  
  //set limits on notes high and low
  if (note1<350){
    note1=350;
    prevNote1=350;
  }
    if (note1>970){
    note1=970;
    prevNote1=970;
  }
  //set amplitude of curves
  int amplitude = map(note1, 600, 1200, 25, 100); 
//  Serial.println(note1);
  
  mapped = map(sensorReading, 300, 875, -10, 10);
  // print the sensor reading so you know its range
  //Serial.println(mapped);
  // map the pitch to the range of the analog input.
  // change the minimum and maximum input numbers below
  // depending on the range your sensor's giving:
  for(int i=0;i<100-amplitude;i++){

      // play the pitch:
      tone(8, note1, 10);
      delay(5);
      note1--;
  }
      
  gap = (prevNote1 - note1);
  gap = gap + mapped;
  
//  Serial.println(gap);
   for(int i=0;i<gap;i++){

      // play the pitch:
      tone(8, note1, 10);
      delay(5);
      note1++;
  }
  prevNote1 = note1;
}

Dark-loving code:

/*
  Based on Pitch follower
 */
 
int sensorReading;
int mapped;
int gap;
int note1 = 700;
int prevNote1=700;

void setup() {
  // initialize serial communications (for debugging only):
  Serial.begin(9600);
  pinMode(3,OUTPUT);
}

void loop() {
  // read the sensor:
  sensorReading = analogRead(A0);
  
  //set limits on notes high and low
  if (note1<350){
    note1=350;
    digitalWrite(3,HIGH);
    prevNote1=350;
  }
    if (note1>970){
    note1=970;
    prevNote1=970;
  }
  //set amplitude of curves
  int amplitude = map(note1, 600, 1200, 25, 100); 
//  Serial.println(note1);
  
  mapped = map(sensorReading, 300, 875, -10, 10);
  // print the sensor reading so you know its range
  //Serial.println(mapped);
  // map the pitch to the range of the analog input.
  // change the minimum and maximum input numbers below
  // depending on the range your sensor's giving:
  if(note1==350){
      
    }
  for(int i=0;i<100-amplitude;i++){
    

      // play the pitch:
      tone(8, note1, 10);
      delay(5);
      note1--;
  }
      
  gap = (prevNote1 - note1);
  gap = gap + mapped;
  
//  Serial.println(gap);
   for(int i=0;i<gap;i++){
if(note1<450){
      digitalWrite(3,LOW);
    }
      // play the pitch:
      tone(8, note1, 10);
      delay(5);
      note1++;
  }
  prevNote1 = note1;
}