From f824ac271c8ebfac66f9b85f7a4d5119d5acfa7e Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 10 Sep 2009 21:55:35 -0400 Subject: audioprogprog --- src/audio_test/audio_test.pde | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/audio_test/audio_test.pde diff --git a/src/audio_test/audio_test.pde b/src/audio_test/audio_test.pde new file mode 100644 index 0000000..bc01e20 --- /dev/null +++ b/src/audio_test/audio_test.pde @@ -0,0 +1,59 @@ +/* + * SQRLS Audio Test + */ + + int speakerOnePin = 5; + int speakerTwoPin = 6; + int motionSensorPin = 7; + +void setup() { + + pinMode(motionSensorPin, INPUT); + pinMode(speakerOnePin, OUTPUT); + pinMode(speakerTwoPin, OUTPUT); + + // Set pins 5&6 to a 62500Hz PWM clock + TCCR0B = TCCR0B & 0b11111000 | 0x01; +} + +void loop() { + + bark(random(50,100)^2/100); + + delay(random(50000,200000)^2/100000); + +} + + +void bark(int ll) { + + /* + for(float j=300; j>0; j-=20) { + //if(random(5) == 1) { + // delayMicroseconds(100); + //} + triangleWave(j*j/300); + } + */ + + for(int j=500; j>200; j-=3000/ll) { + sawWave(j+random(50)); + } + +} + +void triangleWave(int len) { + + for(int i = 0; i < len; i++) { + analogWrite(speakerOnePin, i*255/len); + } + for(int i = 0; i < len; i++) { + analogWrite(speakerOnePin, 255 - i*255/len); + } +} + +void sawWave(int len) { + for(int i = 0; i < len; i++) { + analogWrite(speakerOnePin, i); + } +} -- cgit v1.2.3