/* * 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); } }