Saturday, November 4, 2017

Lab 7 - Introduction to Making Sounds

CLASSWORK:
Simple Speaker Tone
//Specify digital pin on the Arduino that the positive lead of the //speaker is attached. 

int speakerPin = 9; 
void setup() 
}//close setup 

void loop() { 
 /*Tone needs 2 arguments, but can take three 1) Pin# 2) Frequency - this is in hertz (cycles per second) which determines the pitch of the noise made 3) Duration - how long the tone plays */ 

 tone(speakerPin, 1000, 500); 
 delay(1000); 


HOMEWORK:
Surprise Song using pitches.h
/*
 Darude - Sandstorm

 (c) Jordi Agricola 2014

 Speaker on port 8

 */
 #include "pitches.h"

// notes in the melody:

// note durations: 4 = quarter note, 8 = eighth note, etc.:

 int shortTone = 80;
 int longTone = 200;
 int standardDelay = 50;
 int delayBetweenBars = 50;

void setup() {

}

void loop() {
   tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
   delay(shortTone);
  noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, shortTone);
  delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, longTone);
 delay(longTone);
 noTone(8);
 delay(delayBetweenBars);

    tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
   delay(shortTone);
  noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, shortTone);
  delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, longTone);
 delay(longTone);
 noTone(8);
 delay(standardDelay);

     tone(8,  NOTE_E4, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,NOTE_E4, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_E4, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_E4, shortTone);
   delay(shortTone);
  noTone(8);
  delay(standardDelay);
tone(8,  NOTE_E4, shortTone);
  delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_E4, shortTone);
 delay(shortTone);
 noTone(8);
  delay(standardDelay);
tone(8,  NOTE_E4, longTone);
 delay(longTone);
 noTone(8);
 delay(standardDelay);


     tone(8,  NOTE_D4, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,NOTE_D4, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_D4, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_D4, shortTone);
   delay(shortTone);
  noTone(8);
  delay(standardDelay);
tone(8,  NOTE_D4, shortTone);
  delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_D4, shortTone);
 delay(shortTone);
 noTone(8);
  delay(standardDelay);
tone(8,  NOTE_D4, longTone);
 delay(longTone);
 noTone(8);
 delay(standardDelay);

tone(8, NOTE_A3, longTone);
delay(longTone);
 noTone(8);
 delay(standardDelay);

 tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
   delay(shortTone);
  noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, shortTone);
  delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, longTone);
 delay(longTone);
 noTone(8);
 delay(delayBetweenBars);

    tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
   delay(shortTone);
  noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, shortTone);
  delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, longTone);
 delay(longTone);
 noTone(8);
 delay(standardDelay);

 tone(8, NOTE_E4, longTone);
 delay(longTone);
 noTone(8);
 delay(standardDelay);

 tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
   delay(shortTone);
  noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, shortTone);
  delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, longTone);
 delay(longTone);
 noTone(8);
 delay(delayBetweenBars);

    tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
   delay(shortTone);
  noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, shortTone);
  delay(shortTone);
 noTone(8);
 delay(standardDelay);
 tone(8,  NOTE_B3, shortTone);
 delay(shortTone);
 noTone(8);
  delay(standardDelay);
tone(8,  NOTE_B3, longTone);
 delay(longTone);
 noTone(8);
 delay(standardDelay);

tone(8, NOTE_E4, longTone);
 delay(longTone);
 noTone(8);
 delay(standardDelay);


}

No comments:

Post a Comment