-
Notifications
You must be signed in to change notification settings - Fork 0
/
everything_amazing_5.pde
102 lines (79 loc) · 1.72 KB
/
everything_amazing_5.pde
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
EVERYTHING INCREDIBLE
included wm and timing in note
sketches for a piezo based album
Kawandeep Virdee
*/
float pitch = 1000;
int wm = 255;
int s=0;
float dur = 20;
void setup() {
// initialize the digital pin as an output.
// We connect the motor to pin 9
pinMode(9, OUTPUT);
Serial.begin(9600);
analogWrite(9, 0);
}
void loop() {
s+=1;
//define pitch
pitch = coolDoubleTriangles(s);
//define width
wm = prettyCool(s);
//define dur
dur = coolDoubleTriangles(s);
//map it up
pitch = map(pitch,0,42,1000,300);
dur = map(dur, 0, 16, 100 ,10);
wm = map(wm, 0,16,200,255);
//play tone
playTone();
//serial
serialPrint();
}
void playTone(){
float x = 0.0;
float len = dur/1000.0;
while(x<len){
x += 0.001*pitch/1000; //this fixes change in time between notes
//LFO effect sweet interference patterns,
analogWrite(9, wm);
delayMicroseconds(pitch); //its this delay that causes a pitch to be heard
analogWrite(9, 0);
delayMicroseconds(pitch);
}
}
float LFO_pwm(float x){
float y = 255.0 * ( 1.0 + sin(x) )/2.0;
return y;
}
void serialPrint(){
//what comes out
Serial.print(pitch);
Serial.print(" ");
Serial.print(dur);
Serial.print(" ");
Serial.println(wm);
}
int coolDoubleTriangles(int t){
int out = abs(16-((t/2)<<1)%16)*(t%2);
out+= (((t/2)<<1)%16)*((t+1)%2);
return out;
}
int prettyCool(int t){
return abs(16-(t^2)|(t%5)&t^2)%16;
}
int slowIncrease(int t){
int out =((5 + t%3)+ (t>>5) % 42) * (t%2); if(out==0){out=((t>>5)+1%42);}
return out;
}
int triangle(int t){
int out = (t<<1) %16;
return out;
}
int interfere(int t){
int out = ((t<<1)%42 + ((t+t>>4)<<2)%42);
out%=42;
return out;
}