2011年2月26日 星期六

Homework 02: Arduino Piano Show

HW02_01: Button
Turn on and off a LED connected to pin 13 when pressing a pushbutton connected to pin 2.

HW02_02: Speaker
A speaker can generate a specific tone when it receives an electronic wave with a specific Pulse Width. For example, you can hear tone “b” when the speaker receives the following wave.


---------------------------
Tone Table for Speaker
---------------------------
#define c 3830 // 261 Hz
#define d 3400 // 294 Hz
#define e 3038 // 329 Hz
#define f 2864 // 349 Hz
#define g 2550 // 392 Hz
#define a 2272 // 440 Hz
#define b 2028 // 493 Hz
#define C 1912 // 523 Hz

----------------------------------
Program 1: Basic sound program
----------------------------------
int speakerOut = 9;
int tone;

void setup() {
pinMode(speakerOut, OUTPUT);

}

void loop() {

tone = 2028;

digitalWrite(speakerOut,HIGH);
delayMicroseconds(tone / 2);
digitalWrite(speakerOut, LOW);
delayMicroseconds(tone / 2);

}


HW02_3: Arduino Doorbell
The doorbell includes a button and a speaker on Arduino. When you press the button, you can hear a tone from the speaker. You can design a special tone for your doorbell.


HW02_4: Arduino Piano Show
You must cooperate with your partner to finish this assignment. Every one designs four buttons with four tones. Each group has to play a song with your Arduino board. A video is necessary to present your Arduino piano work.

沒有留言:

張貼留言