![](/media/cache/profiles/89a26a363b87a87ac6a94277e841b7f4.50x50_q85.jpg)
Uses *spark d-fuser controller hardware as a USB-DMX interface. Developed for visualising Laurel Pardue’s augmented violin with lights.
Dependencies: DMX mbed spk_oled_ssd1305
Diff: main.cpp
- Revision:
- 2:24d9b7a3073c
- Parent:
- 1:f0cc153fe8d3
- Child:
- 3:642cd9d00b69
--- a/main.cpp Wed May 13 18:35:06 2015 +0000 +++ b/main.cpp Thu May 14 00:43:18 2015 +0000 @@ -33,16 +33,19 @@ // DMX Fixtures -#define kDMX_PARCAN_1 4 -#define kDMX_PARCAN_2 8 -#define kDMX_PARCAN_3 12 -#define kDMX_PARCAN_4 16 +#define kDMX_PARCAN_1 8 - 4 // don't know why but fixtures are four higher than code +#define kDMX_PARCAN_2 12 - 4 +#define kDMX_PARCAN_3 16 - 4 +#define kDMX_PARCAN_4 20 - 4 #define kDMX_PARCAN_R 0 #define kDMX_PARCAN_G 1 #define kDMX_PARCAN_B 2 #define kDMX_PARCAN_LUMA 3 +#define kDMX_HAZER_HAZE 128 +#define kDMX_HAZER_FAN 129 + // MISC Defines #define kStringBufferLength 30 @@ -68,6 +71,7 @@ //// mbed input DigitalIn button(kMBED_DIN_TAP_L); +DigitalIn buttonR(kMBED_DIN_TAP_R); bool buttonLastState; char usbSerialBuffer[kUSBSerialBufferLength]; @@ -97,8 +101,53 @@ // TOBY VIOLIN EXTRAS -float sMax = 0.2; -float sMultiplier = 255.0/sMax; +float sMaxFixed = 0.2; +float sMultiplier = 255.0/sMaxFixed; + +void testDMX() +{ + static char state = 1; + + int address; + + switch (state) + { + case 1: address = kDMX_PARCAN_1; break; + case 2: address = kDMX_PARCAN_2; break; + case 3: address = kDMX_PARCAN_3; break; + case 4: address = kDMX_PARCAN_4; break; + } + + unsigned char parCanData[4]; + parCanData[kDMX_PARCAN_R] = 255; + parCanData[kDMX_PARCAN_G] = 255; + parCanData[kDMX_PARCAN_B] = 255; + parCanData[kDMX_PARCAN_LUMA] = 0; + dmx.put(parCanData, kDMX_PARCAN_1, 4); + dmx.put(parCanData, kDMX_PARCAN_2, 4); + dmx.put(parCanData, kDMX_PARCAN_3, 4); + dmx.put(parCanData, kDMX_PARCAN_4, 4); + + parCanData[kDMX_PARCAN_LUMA] = 255; + dmx.put(parCanData, address, 4); + + if (++state > 4) state = 1; +} + +inline void processData() +{ + float sMax = S1; + if (sMax < S2) sMax = S2; + if (sMax < S3) sMax = S3; + if (sMax < S4) sMax = S4; + + float threshold = sMax * 0.7; + + if (S1 < threshold) S1 = 0; + if (S2 < threshold) S2 = 0; + if (S3 < threshold) S3 = 0; + if (S4 < threshold) S4 = 0; +} void usbSerialReceive(void) { @@ -129,6 +178,13 @@ if (scanCount == 7) { newData = true; + processData(); + } + else if (scanCount == 4) + { + // No bow data + newData = true; + processData(); } else { @@ -219,10 +275,27 @@ char S2DMX = S2 * sMultiplier; char S3DMX = S3 * sMultiplier; char S4DMX = S4 * sMultiplier; - dmx.put(kDMX_PARCAN_1+kDMX_PARCAN_LUMA, S1DMX); - dmx.put(kDMX_PARCAN_2+kDMX_PARCAN_LUMA, S2DMX); - dmx.put(kDMX_PARCAN_3+kDMX_PARCAN_LUMA, S3DMX); - dmx.put(kDMX_PARCAN_4+kDMX_PARCAN_LUMA, S4DMX); +// dmx.put(kDMX_PARCAN_1+kDMX_PARCAN_LUMA, S1DMX); +// dmx.put(kDMX_PARCAN_2+kDMX_PARCAN_LUMA, S2DMX); +// dmx.put(kDMX_PARCAN_3+kDMX_PARCAN_LUMA, S3DMX); +// dmx.put(kDMX_PARCAN_4+kDMX_PARCAN_LUMA, S4DMX); + + unsigned char parCanData[4]; + parCanData[kDMX_PARCAN_R] = 255; + parCanData[kDMX_PARCAN_G] = 255; + parCanData[kDMX_PARCAN_B] = 255; + + parCanData[kDMX_PARCAN_LUMA] = S1DMX; + dmx.put(parCanData, kDMX_PARCAN_1, 4); + + parCanData[kDMX_PARCAN_LUMA] = S2DMX; + dmx.put(parCanData, kDMX_PARCAN_2, 4); + + parCanData[kDMX_PARCAN_LUMA] = S3DMX; + dmx.put(parCanData, kDMX_PARCAN_3, 4); + + parCanData[kDMX_PARCAN_LUMA] = S4DMX; + dmx.put(parCanData, kDMX_PARCAN_4, 4); char dmxSummary[kStringBufferLength]; snprintf(dmxSummary, kStringBufferLength, "S %03u %03u %03u %03u", S1DMX, S2DMX, S3DMX, S4DMX); @@ -236,10 +309,21 @@ // If so, lets update the lastState variable and then send an OSC message buttonLastState = button; - if (button) screen.textToBuffer("Sent: /mbed/button 1",5); - else screen.textToBuffer("Sent: /mbed/button 0",5); + if (button) + { + testDMX(); + screen.textToBuffer("Sent: /mbed/button 1",5); + //dmx.put(kDMX_HAZER_HAZE, 128); + //dmx.put(kDMX_HAZER_FAN, 255); + } + else + { + screen.textToBuffer("Sent: /mbed/button 0",5); + dmx.put(kDMX_HAZER_HAZE, 0); + dmx.put(kDMX_HAZER_FAN, 0); + } } - + // for (int i = 0; i<256; i++) // { // for (int j = 0; j<256; j++)