You aren't signed in     Sign In    Help

Arduino Sound Machine

Arduino Sound Machine by dalager.
Video here: www.youtube.com/watch?v=jITzZrbUEZg

Source here:

/*
* Arduino soundmachine
* by Classy & dalager (http://classy.dk & dalager.com)
*
* Based on tutorial www.arduino.cc/en/Tutorial/PlayMelody
*
* Makes sounds. turn pitch up and down with potmeter, activate with button. No fuzz just noise.
*/

int potPin = 2; // select the input pin for the potentiometer

int val = 0; // variable to store the value coming from the sensor
int duration = 160000;
int speakerOut = 9; // digital out
int rest_count = 100; // pause thing

void setup() {
Serial.begin(9600); // open the serial port to send
pinMode(speakerOut, OUTPUT);
//pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}

void loop() {
val = analogRead(potPin); // read the value from the sensor

playTone(val*5);

delayMicroseconds(5000);
}


void playTone(int tone) {
long elapsed_time = 0;
Serial.println(tone);
if (tone > 0) { // if this isn't a Rest beat, while the tone has
// played less long than 'duration', pulse speaker HIGH and LOW
while (elapsed_time < duration) {

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

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

// Keep track of how long we pulsed
elapsed_time += (tone);
}
}
else { // Rest beat; loop times delay
for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
delayMicroseconds(duration);
}
}

Comments

view profile

clauspeterdahl says:

It was all you, Dalager - but I'm so happy to have the kit here at home now
Posted 13 months ago. ( permalink )

view profile

dalager  Pro User  says:

Home automation toolkit?
Posted 13 months ago. ( permalink )

Would you like to comment?

Sign up for a free account, or sign in (if you're already a member).

[?]
view photos Uploaded on June 28, 2008
by dalager

dalager's photostream

517
uploads

Tags

Additional Information

AttributionNoncommercial Some rights reserved Anyone can see this photo

Add to your map