Permalink
Browse files

initial setup from roskilde festival 2010

  • Loading branch information...
madshobye committed Jul 17, 2011
0 parents commit 89ce7c6092a34bd0092613c14012d4744d7b1994
BIN .DS_Store
Binary file not shown.
@@ -0,0 +1,225 @@
+// my app | ICNAPP | ICNlibrary |
+// | | |
+// write code | modify | don't touch |
+// here | as needed | bits & c. |
+
+#define RUNTIME
+#include <DmxSimple.h>
+
+void setup()
+{
+#ifdef RUNTIME
+ netstart(); // KEEP THIS LINE
+#else
+ Serial.begin(9600);
+#endif
+ DmxSimple.usePin(3);
+
+ DmxSimple.maxChannel(4);
+}
+
+/* OUTPUT
+ - 6 combi
+ - 6 combiEnergy
+ - 6 combiChange
+ - 4 ligths
+ - combiTotal
+
+ TODO
+ - langsommere combiEnergy
+ - mere lys
+ - hurtigere combiChange
+
+ */
+#define range 254
+long time = 0;
+
+float combi[6];
+float combiOld[6];
+float combiEnergy[6];
+float combiTotal =0;
+float combiChange[6];
+float ligths[4];
+int maxSlider = 3057;
+int cutoffSlider = 100;
+void loop()
+{
+
+
+ /// RESET
+
+ for(int i = 0;i<4;i++)
+ {
+ ligths[i] = 0;
+ }
+ for(int i = 0;i<6;i++)
+ {
+ combiOld[i] = combi[i];
+ }
+
+
+ /// READ DATA
+ int index = 0;
+ int lightTotal = 0;
+ for(int i = 0; i < 3 ;i ++)
+ {
+ for(int b = i+1; b < 4; b++)
+ {
+ // RAW READ
+ combi[index] = mapIt(touchRead(i,b) - cutoffSlider, maxSlider);
+
+
+ ligths[i] = ligths[i] + combi[index];
+ ligths[b] = ligths[b] + combi[index];
+ lightTotal = lightTotal + combi[index];
+ index++;
+
+ }
+
+ }
+
+ lightTotal = lightTotal / 6.0f;
+
+ // map sums
+
+
+ for(int i=0;i < 4;i++)
+ {
+ ligths[i] = ligths[i] / 3.0f;
+
+ }
+
+ /// PROCESS DATA
+
+ combiTotal = combiTotal *0.7 + lightTotal * 0.2;
+ for(int i = 0; i < 6 ;i ++)
+ {
+ combiChange[i] = combiChange[i] * 0.8f + (makeEven(combi[i] - combiOld[i]))/2.0f;
+ combiChange[i] = mapIt(combiChange[i],range);
+ }
+ for(int i = 0; i < 6 ;i ++)
+ {
+ if(combi[i] > 20)
+ combiEnergy[i] = combiEnergy[i] + combi[i]*0.08;
+ else
+ combiEnergy[i] = combiEnergy[i] * 0.6;
+
+ combiEnergy[i] = mapIt(combiEnergy[i],range);
+ }
+
+
+ /// SEND DATA
+ index = 0;
+
+ // SEND DATA
+
+ /* OUTPUT
+ - 6 combi
+ - 6 combiEnergy
+ - 6 combiChange
+ - 4 ligths
+ - combiTotal
+
+
+ */
+
+ for(int i = 0; i < 6; i++)
+ {
+ sendData(index++,combi[i]);
+
+ }
+ for(int i = 0; i < 6; i++)
+ {
+ sendData(index++,combiEnergy[i]);
+
+ }
+ for(int i = 0; i < 6;i++)
+ {
+ sendData(index++,combiChange[i]);
+
+ }
+
+ for(int i = 0; i < 4;i++)
+ {
+ sendData(index++,ligths[i]);
+
+ }
+ sendData(index++,combiTotal);
+ sendDataEnd();
+
+ // DMX
+ if(time < millis())
+ {
+
+ time = millis() + 100;
+ for(int i=0;i<4;i++)
+ {
+ DmxSimple.write(i+1, ligths[i]*255.0f/range);
+ }
+
+ }
+ /// DMX
+
+
+}
+
+float makeEven(float value)
+{
+ if (value >0)
+ {
+ return value;
+ }
+ return value * -1;
+
+}
+void sendData(int index, float value)
+{
+
+#ifdef RUNTIME
+ writeReturnInt(index,(int)value);
+#else
+ Serial.print((int)value);
+ Serial.print(" ");
+#endif
+}
+
+void sendDataEnd()
+{
+#ifndef RUNTIME
+ Serial.println("");
+#endif
+}
+
+
+float mapIt(int value, int maximum)
+{
+ return max(0.0f,min(range,((float)value/(float)maximum * range)));
+
+}
+
+int touchRead(int pin1, int pin2)
+{
+ int sum=0;
+ for(int i=0; i < 10; i++)
+ {
+ pinMode(pin1+14, OUTPUT);
+
+
+ digitalWrite(pin1 + 14,HIGH);
+ delayMicroseconds(10);
+ int high = analogRead(pin2);
+
+ digitalWrite(pin1 + 14,LOW);
+ delayMicroseconds(10);
+ int low = analogRead(pin2);
+
+
+ pinMode(pin1+14, INPUT);
+ digitalWrite(pin1 + 14,LOW);
+ sum = sum +high-low;
+ }
+
+ return (int)((float)sum/4.0f);
+
+}
+
@@ -0,0 +1,90 @@
+ #ifdef RUNTIME
+// *************************************************************************************
+// ICN APP CONFIG
+// *************************************************************************************
+
+#define icn_my_talkPin 12
+#define icn_my_address 16 // my unique node ID
+#define icn_my_appName "Electrolume" // app name: 32 chars max
+#define icn_my_appAuthor "Mads Høbye" // app author: 32 chars max
+#define icn_my_appVersion 101
+
+#define icn_my_params_in_num 2 // number of control parameters accepted from host
+#define icn_my_params_in_type int14 // type of control parameters accepted from host
+ // valid options are:
+ // int8, int14, float8, float14, sfloat8, sfloat14
+
+#define icn_my_params_out_num 23 // number of data items returned to host
+#define icn_my_params_out_type int8 // type of data items returned to host
+ // valid options are:
+ // int8, int14, float8, float14, sfloat8, sfloat14
+
+#define icn_my_signals_num 0 // number of signals supported
+
+// *************************************************************************************
+
+// #define icn_mega128 // UNCOMMENT IF WIRING BOARD USED
+
+// WIRING BOARD OPTION ONLY WORKS WITH MODIFIED WIRING VERSION AVAILABLE FROM ILLUTRON
+// The PDE preprocessor in the hacked version omits inclusion of hardwareserial.h
+
+// *************************************************************************************
+// ICN APP HOOKS
+// *************************************************************************************
+
+int icn_app_start(int sender, int socket, boolean broadcast)
+{
+ // call from network with standard signal "APP START"
+ // if broadcast is high then signal is for everybody, not just me
+ return 0;
+}
+
+int icn_app_stop(int sender, int socket, boolean broadcast)
+{
+ // call from network with standard signal "APP STOP"
+ // if broadcast is high then signal is for everybody, not just me
+ return 0;
+}
+
+int icn_app_reset(int sender, int socket, boolean broadcast)
+{
+ // call from network with standard signal "APP RESET"
+ // if broadcast is high then signal is for everybody, not just me
+ return 0;
+}
+
+int icn_app_user(int sender, int socket, int length, unsigned char *usermessage, boolean broadcast)
+{
+ // user message of specified length available in usermessage buffer.
+ return 0;
+}
+
+int icn_app_signal(int sender, int socket, int signal, boolean broadcast)
+{
+ return 0;
+}
+
+int icn_app_param_changed(int sender, int socket, int index, boolean broadcast)
+{
+ // control parameter was updated remotely!
+ if (index ==0)
+ {
+ maxSlider = readRemoteInt(0);
+ }
+ else if(index==1)
+ {
+ cutoffSlider = readRemoteInt(1);
+ }
+ return 0;
+}
+
+void icn_app_dumped(int sender, int socket)
+{
+ // return buffer was dumped
+}
+
+void icn_app_spoolStopped(int spoolPort, boolean myBumper)
+{
+ // spool playback complete event
+}
+ #endif
Oops, something went wrong.

0 comments on commit 89ce7c6

Please sign in to comment.