COLL 142 - Week 10

Speaker Dirty to Me

Salvatore "Sal" Testa /@saltesta14

But first...

Final project has changed

Aim for projects

  • incorporate maker technologies
  • within time constraints
  • on budget

The catapult was...

  • too mechanical.
  • too time consuming.
  • too to pricey.

Final Project

What is a speaker?

Musical Magnets

How do we make sounds with them?

High Level Old School GIF

Annoying Demo


int SPEAKER = P2_0;
void setup()
{
  pinMode(SPEAKER, OUTPUT);
}
int waittime = 2;
void loop()
{
  digitalWrite(SPEAKER,HIGH);
  delay(waittime);
  digitalWrite(SPEAKER,LOW);
  delay(waittime);
} // Oh jeez, make it stop
                       

How can we make different sounds?

Change the amount of time it's high/low


int SPEAKER = P2_0;
int highDelay = 2;
int lowDelay = 3;
void setup()
{
  pinMode(SPEAKER, OUTPUT);
}
void loop()
{
  digitalWrite(SPEAKER,HIGH);
  delay(highDelay);
  digitalWrite(SPEAKER,LOW);
  delay(lowDelay);
} // Sounds like the Brown fire alarm
                       

Are there any nice, pre-made helpers?

Yes

Built-in tone method

What are we doing today?

Explore digital signal


int SPEAKER = P2_0;
int BUTTON = P1_3;
int highDelay = 2;
int lowDelay = 3;
void setup()
{
  pinMode(SPEAKER, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);
}
void loop()
{
  if(digitalRead(BUTTON) == LOW) { // keep your friends
    digitalWrite(SPEAKER,HIGH);
    delay(highDelay);
    digitalWrite(SPEAKER,LOW);
    delay(lowDelay);
  }
}
                       

Make your own musical keyboard!

Microcontroller and Processing

Reach goal: make your own song

Modify toneMelody (from the examples)