X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=arduino%2FSoundMix%2FSoundMix.pde;fp=arduino%2FSoundMix%2FSoundMix.pde;h=6466151b297d808de82ffe1d980beab6a8e553fa;hb=a3a3e37495447af1bfafbf29b36e894bab90661b;hp=0000000000000000000000000000000000000000;hpb=7189c931e5db356ca29fb34d0ccd376357f54446;p=mirrors%2FPrograms.git diff --git a/arduino/SoundMix/SoundMix.pde b/arduino/SoundMix/SoundMix.pde new file mode 100755 index 0000000..6466151 --- /dev/null +++ b/arduino/SoundMix/SoundMix.pde @@ -0,0 +1,36 @@ +/* + * Bit-bang sound + * <~~Harvie 2oo8 + */ + +#define sndout 13 + +char mixer; + +void sound(char sndpin, float freq, float duration) { //Play bit-bang sound + if(duration<=0) return; if(freq<=0) { delay(duration); return; } + freq=((1000000/2)/freq); //Convert freq to delay (us) + duration*=1000; //Convert duration to us + pinMode(sndpin, OUTPUT); + for(;duration>0;duration-=2*freq) { + digitalWrite(sndpin, HIGH); delayMicroseconds(freq); + digitalWrite(sndpin, LOW); delayMicroseconds(freq); + } + pinMode(sndpin, INPUT); //Close pin to avoid noise (optional) +} + +void setup() { // run once, when the sketch starts + pinMode(sndout, OUTPUT); + pinMode(sndout-1, INPUT); +} + +void loop() { // run over and over again + //delay(10000); return;//Silence! I'll kill you! + //float i=0; while(1) { sound(sndout, sin(i+=0.01)*550, 10); sound(sndout, cos(i)*400, 10); } + digitalWrite(sndout, digitalRead(sndout-1)); + /* int octave, duration; + char melody[]="CCDEECCFFAAGGE-CCDEGGEFEDDCC-CCDEECCFFAAGGE-CCDEGGEFEDDC"; octave=1; duration=300; //Bob Marley's Redemption song - intro ;D + play_melody(sndout, melody, octave, duration); */ + //delay(2000); +} +