Moved whole Arduino sketchbook to GIT (nothing interesting :-)
[mirrors/Programs.git] / arduino / SoundMix / SoundMix.pde
CommitLineData
a3a3e374
H
1/*
2 * Bit-bang sound
3 * <~~Harvie 2oo8
4 */
5
6#define sndout 13
7
8char mixer;
9
10void sound(char sndpin, float freq, float duration) { //Play bit-bang sound
11 if(duration<=0) return; if(freq<=0) { delay(duration); return; }
12 freq=((1000000/2)/freq); //Convert freq to delay (us)
13 duration*=1000; //Convert duration to us
14 pinMode(sndpin, OUTPUT);
15 for(;duration>0;duration-=2*freq) {
16 digitalWrite(sndpin, HIGH); delayMicroseconds(freq);
17 digitalWrite(sndpin, LOW); delayMicroseconds(freq);
18 }
19 pinMode(sndpin, INPUT); //Close pin to avoid noise (optional)
20}
21
22void setup() { // run once, when the sketch starts
23 pinMode(sndout, OUTPUT);
24 pinMode(sndout-1, INPUT);
25}
26
27void loop() { // run over and over again
28 //delay(10000); return;//Silence! I'll kill you!
29 //float i=0; while(1) { sound(sndout, sin(i+=0.01)*550, 10); sound(sndout, cos(i)*400, 10); }
30 digitalWrite(sndout, digitalRead(sndout-1));
31 /* int octave, duration;
32 char melody[]="CCDEECCFFAAGGE-CCDEGGEFEDDCC-CCDEECCFFAAGGE-CCDEGGEFEDDC"; octave=1; duration=300; //Bob Marley's Redemption song - intro ;D
33 play_melody(sndout, melody, octave, duration); */
34 //delay(2000);
35}
36
This page took 0.175146 seconds and 4 git commands to generate.