Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 272 lines (195 sloc) 4.099 kb
89ce7c60 »
2011-07-17 initial setup from roskilde festival 2010
1 // my app | ICNAPP | ICNlibrary |
2 // | | |
3 // write code | modify | don't touch |
4 // here | as needed | bits & c. |
5
6 #define RUNTIME
7 #include <DmxSimple.h>
8
9 void setup()
10 {
11 #ifdef RUNTIME
12 netstart(); // KEEP THIS LINE
13 #else
14 Serial.begin(9600);
15 #endif
16 DmxSimple.usePin(3);
17
18 DmxSimple.maxChannel(4);
19 }
20
21 /* OUTPUT
22 - 6 combi
23 - 6 combiEnergy
24 - 6 combiChange
25 - 4 ligths
26 - combiTotal
27
28 TODO
29 x langsommere combiEnergy
30 - mere lys
31 x hurtigere combiChange
32
33 */
34 #define range 254
35 long time = 0;
36
37 float combi[6];
38 float combiOld[6];
39 float combiEnergy[6];
40 float combiTotal =0;
41 float combiChange[6];
42
43 float ligths[4];
44 float ligths_dmx[4];
45
46 float maxSlider =3015;
47 float cutoffSlider = 100;
48 float factorLightSlider = 1.9f;
49 float changeSLider = 1.3f;
50 float energySlider = 0.3;
51
52 /*
53 control sliders:
54 maxSlider
55 cutoffSlider
56 factorLight
57 changeSlider
58 energySlider
59
60
61
62 */
63 void loop()
64 {
65
66
67 /// RESET
68
69 for(int i = 0;i<4;i++)
70 {
71 ligths[i] = 0;
72 }
73 for(int i = 0;i<6;i++)
74 {
75 combiOld[i] = combi[i];
76 }
77
78
79 /// READ DATA
80 int index = 0;
81 int lightTotal = 0;
82 for(int i = 0; i < 3 ;i ++)
83 {
84 for(int b = i+1; b < 4; b++)
85 {
86 // RAW READ
87 combi[index] = mapIt(touchRead(i,b) - cutoffSlider, maxSlider);
88
89
90 ligths[i] = ligths[i] + combi[index];
91 ligths[b] = ligths[b] + combi[index];
92 lightTotal = lightTotal + combi[index];
93 index++;
94
95 }
96
97 }
98
99 lightTotal = lightTotal / 6.0f;
100
101 // map sums
102
103
104 for(int i=0;i < 4;i++)
105 {
106 ligths[i] = ligths[i] / 3.0f;
107
108 }
109
110 /// PROCESS DATA
111
112 combiTotal = combiTotal *0.7 + lightTotal * 0.2;
113 for(int i = 0; i < 6 ;i ++)
114 {
115 combiChange[i] = combiChange[i] * 0.92f + (makeEven(combi[i] - combiOld[i]))/changeSLider;
116 combiChange[i] = mapIt(combiChange[i],range);
117 }
118 for(int i = 0; i < 6 ;i ++)
119 {
120 if(combi[i] > 40)
121 combiEnergy[i] = combiEnergy[i] + combi[i]*energySlider;
122 else
123 combiEnergy[i] = combiEnergy[i] * 0.6;
124
125 combiEnergy[i] = mapIt(combiEnergy[i],range);
126 }
127
128
129 /// SEND DATA
130 index = 0;
131
132 // SEND DATA
133
134 /* OUTPUT
135 - 6 combi
136 - 6 combiEnergy
137 - 6 combiChange
138 - 4 ligths
139 - combiTotal
140
141
142 */
143
144 for(int i = 0; i < 6; i++)
145 {
146 sendData(index++,combi[i]);
147
148 }
149 for(int i = 0; i < 6; i++)
150 {
151 sendData(index++,combiEnergy[i]);
152
153 }
154 for(int i = 0; i < 6;i++)
155 {
156 sendData(index++,combiChange[i]);
157
158 }
159
160 for(int i = 0; i < 4;i++)
161 {
162 sendData(index++,ligths[i]);
163
164 }
165 sendData(index++,combiTotal);
166 sendDataEnd();
167
168 //add noise
169 for(int i = 0; i < 4;i++)
170 {
171 ligths_dmx[i] *= 0.6;
172
173 if(ligths[i]>0.2 &&random(0.0f,100.0f) > 96.9f)
174 {
175 ligths_dmx[i] = max(ligths_dmx[i],random(30,255));
176 }
177
178 ligths_dmx[i] = max(ligths_dmx[i],min(255,ligths[i]*255.0f/range*factorLightSlider));
179
180
181
182 }
183
184 // DMX
185 if(time < millis())
186 {
187
188 time = millis() + 20;
189 for(int i=0;i<4;i++)
190 {
191 DmxSimple.write(i+1, min(ligths_dmx[i],255));
192 }
193
194 }
195 /// DMX
196
197
198 }
199
200 float makeEven(float value)
201 {
202 if (value >0)
203 {
204 return value;
205 }
206 return value * -1;
207
208 }
209 void sendData(int index, float value)
210 {
211
212 #ifdef RUNTIME
213 writeReturnInt(index,(int)value);
214 #else
215 Serial.print((int)value);
216 Serial.print(" ");
217 #endif
218 }
219
220 void sendDataEnd()
221 {
222 #ifndef RUNTIME
223 Serial.println("");
224 #endif
225 }
226
227
228 float mapIt(int value, int maximum)
229 {
230 return max(0.0f,min(range,((float)value/(float)maximum * range)));
231
232 }
233
234 int touchRead(int pin1, int pin2) // Brug analoge tal
235 {
236 int sum=0; // summerings int
237
238 for(int i=0; i < 10; i++) // 10 samples - ændre efter behov.
239 {
240 pinMode(pin1+14, OUTPUT); // pin1 til output
241
242
243 digitalWrite(pin1 + 14,HIGH);
244 delayMicroseconds(10);
245 int high = analogRead(pin2);
246
247 digitalWrite(pin1 + 14,LOW);
248 delayMicroseconds(10);
249 int low = analogRead(pin2);
250
251
252 pinMode(pin1+14, INPUT);
253 digitalWrite(pin1 + 14,LOW);
254 sum = sum +high-low;
255 }
256
257 return (int)((float)sum/4.0f);
258
259 }
260
261 /*
262
263 if(touchRead(0,1)>1000) // analogue 0,1
264 {
265
266
267 }
268
269
270 */
271
Something went wrong with that request. Please try again.