aboutsummaryrefslogtreecommitdiffstats
path: root/src/audio_test/audio_test.pde
blob: bc01e20b4c87e1a55fa8ad49e2e1f43ca57ab4d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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);
  }
}