Monday, September 27, 2010

code

/*
Melody

Plays a melody

circuit:
* 8-ohm speaker on digital pin 8

created 21 Jan 2010
by Tom Igoe

http://arduino.cc/en/Tutorial/Tone

*/
#include "pitches.h"

int sensorPin = 0; // select the input pin for the potentiometer
int ledPin = 11; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

// notes in the melody:
/*int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
*/
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 12 };

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);

// iterate over the notes of the melody:

}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
//digitalWrite(ledPin, HIGH);
// stop the program for
milliseconds:
//delay(sensorValue);
// turn the ledPin off:
//digitalWrite(ledPin, LOW);
// stop the program for for
milliseconds:
delay(sensorValue);

for (int thisNote = 0; thisNote < note =" 1000" note =" 1000/8," noteduration =" sensorValue/noteDurations[thisNote];" pausebetweennotes =" noteDuration">

No comments:

Post a Comment