|
|
@ -22,7 +22,7 @@ |
|
|
|
#define DEBUG 1 |
|
|
|
#define DEBUG 1 |
|
|
|
|
|
|
|
|
|
|
|
#define SENSOR_SCHED 10 |
|
|
|
#define SENSOR_SCHED 10 |
|
|
|
#define WORKER_SCHED 100 |
|
|
|
#define DMX_COLOR_CHANGER_SCHED 100 |
|
|
|
#define LED_SCHED 50 |
|
|
|
#define LED_SCHED 50 |
|
|
|
#define LEVEL_CHECK_SCHED 100 |
|
|
|
#define LEVEL_CHECK_SCHED 100 |
|
|
|
#define DEBUG_SCHED 500 |
|
|
|
#define DEBUG_SCHED 500 |
|
|
@ -35,8 +35,8 @@ |
|
|
|
#define DMX_MAX_CHANNEL 512 |
|
|
|
#define DMX_MAX_CHANNEL 512 |
|
|
|
#define MAX_VOL_LEVEL 30 |
|
|
|
#define MAX_VOL_LEVEL 30 |
|
|
|
#define MAX_DMX_LEVEL 255 |
|
|
|
#define MAX_DMX_LEVEL 255 |
|
|
|
#define MAX_DMX_SPOTS 2 |
|
|
|
|
|
|
|
#define DMX_FOG_MACHINE_ADDRESS 100 |
|
|
|
#define DMX_FOG_MACHINE_ADDRESS 100 |
|
|
|
|
|
|
|
#define MAX_RAND_WHITE_LEVEL 128 |
|
|
|
|
|
|
|
|
|
|
|
#define DMX_BRIGHTNESS 0 |
|
|
|
#define DMX_BRIGHTNESS 0 |
|
|
|
#define DMX_FADE_TIME 1 |
|
|
|
#define DMX_FADE_TIME 1 |
|
|
@ -44,9 +44,10 @@ |
|
|
|
#define DMX_FOG_LEVEL 3 |
|
|
|
#define DMX_FOG_LEVEL 3 |
|
|
|
|
|
|
|
|
|
|
|
#define MIN_DMX_FADE_TIME 1 |
|
|
|
#define MIN_DMX_FADE_TIME 1 |
|
|
|
#define MAX_DMX_FADE_TIME 10 |
|
|
|
#define MAX_DMX_FADE_TIME 15 |
|
|
|
#define MIN_DMX_HOLD_TIME 5 |
|
|
|
#define MIN_DMX_HOLD_TIME 3 |
|
|
|
#define MAX_DMX_HOLD_TIME 15 |
|
|
|
#define MAX_DMX_HOLD_TIME 30 |
|
|
|
|
|
|
|
#define ON_OFF_FADE_TIME 1 |
|
|
|
|
|
|
|
|
|
|
|
// Arduino pins
|
|
|
|
// Arduino pins
|
|
|
|
#define POTI1_PIN A1 |
|
|
|
#define POTI1_PIN A1 |
|
|
@ -84,6 +85,8 @@ typedef struct { |
|
|
|
float values[4] = { 0.0, 0.0, 0.0, 0.0 }; |
|
|
|
float values[4] = { 0.0, 0.0, 0.0, 0.0 }; |
|
|
|
} dmx_spot; |
|
|
|
} dmx_spot; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_DMX_SPOTS 2 |
|
|
|
|
|
|
|
|
|
|
|
dmx_spot spot[MAX_DMX_SPOTS]; |
|
|
|
dmx_spot spot[MAX_DMX_SPOTS]; |
|
|
|
|
|
|
|
|
|
|
|
// schedular
|
|
|
|
// schedular
|
|
|
@ -147,11 +150,11 @@ void show_led(void) { |
|
|
|
analogWrite(LED_PIN, LED_PLAY_BRIGHTNESS); |
|
|
|
analogWrite(LED_PIN, LED_PLAY_BRIGHTNESS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void worker(void) { |
|
|
|
void dmx_auto_colorchanger(void) { |
|
|
|
// DMX auto Fade
|
|
|
|
// DMX auto Fade
|
|
|
|
|
|
|
|
|
|
|
|
if (light_state != NORMAL) |
|
|
|
//if (light_state != NORMAL)
|
|
|
|
return; |
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
|
|
for (uint8_t s = 0; s < MAX_DMX_SPOTS; s++) { |
|
|
|
for (uint8_t s = 0; s < MAX_DMX_SPOTS; s++) { |
|
|
|
uint8_t diff_counter = 0; |
|
|
|
uint8_t diff_counter = 0; |
|
|
@ -165,40 +168,65 @@ void worker(void) { |
|
|
|
} |
|
|
|
} |
|
|
|
if (diff_counter != 0) { |
|
|
|
if (diff_counter != 0) { |
|
|
|
// start hold timer
|
|
|
|
// start hold timer
|
|
|
|
int8_t start = MIN_DMX_FADE_TIME + MIN_DMX_FADE_TIME * poti_level[1] / 255.0 * 4; |
|
|
|
if (light_state != NORMAL) |
|
|
|
spot[s].steps = random(start, start + ((MAX_DMX_HOLD_TIME - start) * poti_level[DMX_HOLD_TIME] / 255.0)) * 1000 / WORKER_SCHED; |
|
|
|
continue; |
|
|
|
|
|
|
|
int8_t start = MIN_DMX_HOLD_TIME + MIN_DMX_HOLD_TIME * poti_level[1] / 255.0 * 4; |
|
|
|
|
|
|
|
spot[s].steps = random(start, start + ((MAX_DMX_HOLD_TIME - start) * poti_level[DMX_HOLD_TIME] / 255.0)) * 1000 / DMX_COLOR_CHANGER_SCHED; |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.print(F("Spot ")); |
|
|
|
Serial.print(F("Spot ")); |
|
|
|
Serial.print(s, DEC); |
|
|
|
Serial.print(s, DEC); |
|
|
|
Serial.print(F(" holding for ")); |
|
|
|
Serial.print(F(" holding for ")); |
|
|
|
Serial.print(spot[s].steps * WORKER_SCHED / 1000, DEC); |
|
|
|
Serial.print(spot[s].steps * DMX_COLOR_CHANGER_SCHED / 1000, DEC); |
|
|
|
Serial.println(F(" seconds")); |
|
|
|
Serial.println(F(" seconds")); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// new random values
|
|
|
|
// new random values
|
|
|
|
|
|
|
|
if (light_state != NORMAL) |
|
|
|
|
|
|
|
continue; |
|
|
|
RGBConverter color_converter; |
|
|
|
RGBConverter color_converter; |
|
|
|
uint8_t rgb[3]; |
|
|
|
uint8_t rgb[3]; |
|
|
|
int8_t start = MIN_DMX_FADE_TIME + MIN_DMX_FADE_TIME * poti_level[1] / 255.0 * 4; |
|
|
|
uint8_t start = MIN_DMX_FADE_TIME + MIN_DMX_FADE_TIME * poti_level[2] / 255.0 * 4; |
|
|
|
|
|
|
|
|
|
|
|
spot[s].steps = random(start, start + ((MAX_DMX_FADE_TIME - start) * poti_level[DMX_FADE_TIME] / 255.0)) * 1000 / WORKER_SCHED; |
|
|
|
|
|
|
|
color_converter.hsvToRgb(random(0, 1024) / 1024.0, 1.0, 1.0, rgb); |
|
|
|
color_converter.hsvToRgb(random(0, 1024) / 1024.0, 1.0, 1.0, rgb); |
|
|
|
for (uint8_t i = 0; i < 3; i++) |
|
|
|
|
|
|
|
spot[s].diff[i] = (rgb[i] - spot[s].values[i]) / spot[s].steps; |
|
|
|
if (spot[s].dmx_type > 3) |
|
|
|
spot[s].diff[3] = (random(0, 128) - spot[3].values[3]) / 255.0; |
|
|
|
set_rgbw(&spot[s], random(start, start + ((MAX_DMX_FADE_TIME - start) * poti_level[DMX_FADE_TIME] / 255.0)), rgb, random(0, MAX_RAND_WHITE_LEVEL)); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
set_rgb(&spot[s], random(start, start + ((MAX_DMX_FADE_TIME - start) * poti_level[DMX_FADE_TIME] / 255.0)), rgb); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.print(F("Spot ")); |
|
|
|
Serial.print(F("Spot ")); |
|
|
|
Serial.print(s, DEC); |
|
|
|
Serial.print(s, DEC); |
|
|
|
Serial.print(F(" changing color for ")); |
|
|
|
Serial.print(F(" changing color to R[")); |
|
|
|
Serial.print(spot[s].steps * WORKER_SCHED / 1000, DEC); |
|
|
|
Serial.print(spot[s].values[0], 2); |
|
|
|
|
|
|
|
Serial.print(F("] G[")); |
|
|
|
|
|
|
|
Serial.print(spot[s].values[1], 2); |
|
|
|
|
|
|
|
Serial.print(F("] B[")); |
|
|
|
|
|
|
|
Serial.print(spot[s].values[2], 2); |
|
|
|
|
|
|
|
if (spot[s].dmx_type > 3) { |
|
|
|
|
|
|
|
Serial.print(F("] W[")); |
|
|
|
|
|
|
|
Serial.print(spot[s].values[3], 2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Serial.print(F("] for ")); |
|
|
|
|
|
|
|
Serial.print(spot[s].steps * DMX_COLOR_CHANGER_SCHED / 1000, DEC); |
|
|
|
Serial.println(F(" seconds")); |
|
|
|
Serial.println(F(" seconds")); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for (uint8_t i = 0; i < spot[s].dmx_type; i++) { |
|
|
|
for (uint8_t i = 0; i < spot[s].dmx_type; i++) { |
|
|
|
spot[s].values[i] += spot[s].diff[i]; |
|
|
|
if (spot[s].diff[i] != 0.0) { |
|
|
|
DmxSimple.write(spot[s].address + i, uint8_t(spot[s].values[i] * poti_level[DMX_BRIGHTNESS] / 255.0 + 0.5)); |
|
|
|
spot[s].values[i] += spot[s].diff[i]; |
|
|
|
|
|
|
|
if (spot[s].values[i] > 255.0) |
|
|
|
|
|
|
|
spot[s].values[i] = 255.0; |
|
|
|
|
|
|
|
else if (spot[s].values[i] < 0) |
|
|
|
|
|
|
|
spot[s].values[i] = 0.0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DmxSimple.write(spot[s].address + i, uint8_t(spot[s].values[i] * poti_level[DMX_BRIGHTNESS] / 255.0 + 0.5)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
/* Serial.print(F("Spot "));
|
|
|
|
Serial.print(F("Spot ")); |
|
|
|
Serial.print(s, DEC); |
|
|
|
Serial.print(s, DEC); |
|
|
|
Serial.print(F(" color ")); |
|
|
|
Serial.print(F(" color ")); |
|
|
|
Serial.print(i, DEC); |
|
|
|
Serial.print(i, DEC); |
|
|
@ -207,8 +235,9 @@ void worker(void) { |
|
|
|
Serial.print(F(" diff ")); |
|
|
|
Serial.print(F(" diff ")); |
|
|
|
Serial.print(spot[s].diff[i], 4); |
|
|
|
Serial.print(spot[s].diff[i], 4); |
|
|
|
Serial.print(F(" value ")); |
|
|
|
Serial.print(F(" value ")); |
|
|
|
Serial.println(spot[s].values[i], 4);*/ |
|
|
|
Serial.println(spot[s].values[i], 4); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
spot[s].steps--; |
|
|
|
spot[s].steps--; |
|
|
@ -312,9 +341,14 @@ void do_button_short(uint8_t b) { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
light_state = WHITE; |
|
|
|
light_state = WHITE; |
|
|
|
for (uint8_t s = 0; s < MAX_DMX_SPOTS; s++) { |
|
|
|
for (uint8_t s = 0; s < MAX_DMX_SPOTS; s++) { |
|
|
|
|
|
|
|
uint8_t rgb[3] = { 255, 255, 255 }; |
|
|
|
for (uint8_t i = 0; i < spot[s].dmx_type; i++) |
|
|
|
for (uint8_t i = 0; i < spot[s].dmx_type; i++) |
|
|
|
DmxSimple.write(spot[s].address + i, 255); |
|
|
|
if (spot[s].dmx_type > 3) |
|
|
|
|
|
|
|
set_rgbw(&spot[s], ON_OFF_FADE_TIME, rgb, 255); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
set_rgb(&spot[s], ON_OFF_FADE_TIME, rgb); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.println(F("Light: OFF")); |
|
|
|
Serial.println(F("Light: OFF")); |
|
|
@ -337,8 +371,12 @@ void do_button_short(uint8_t b) { |
|
|
|
|
|
|
|
|
|
|
|
if (light_state == OFF) { |
|
|
|
if (light_state == OFF) { |
|
|
|
for (uint8_t s = 0; s < MAX_DMX_SPOTS; s++) { |
|
|
|
for (uint8_t s = 0; s < MAX_DMX_SPOTS; s++) { |
|
|
|
|
|
|
|
uint8_t rgb[3] = { 0, 0, 0 }; |
|
|
|
for (uint8_t i = 0; i < spot[s].dmx_type; i++) |
|
|
|
for (uint8_t i = 0; i < spot[s].dmx_type; i++) |
|
|
|
DmxSimple.write(spot[s].address + i, 0); |
|
|
|
if (spot[s].dmx_type > 3) |
|
|
|
|
|
|
|
set_rgbw(&spot[s], ON_OFF_FADE_TIME, rgb, 0); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
set_rgb(&spot[s], ON_OFF_FADE_TIME, rgb); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -404,6 +442,18 @@ uint8_t poti_pin_by_number(byte n) { |
|
|
|
return (0); |
|
|
|
return (0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void set_rgbw(dmx_spot* spot, uint8_t fade, uint8_t* rgb, uint8_t w) { |
|
|
|
|
|
|
|
spot->steps = fade * 1000 / DMX_COLOR_CHANGER_SCHED; |
|
|
|
|
|
|
|
spot->diff[3] = (w - spot->values[3]) / spot->steps; |
|
|
|
|
|
|
|
set_rgb(spot, fade, rgb); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void set_rgb(dmx_spot* spot, uint8_t fade, uint8_t* rgb) { |
|
|
|
|
|
|
|
spot->steps = fade * 1000 / DMX_COLOR_CHANGER_SCHED; |
|
|
|
|
|
|
|
for (uint8_t i = 0; i < 3; i++) |
|
|
|
|
|
|
|
spot->diff[i] = (rgb[i] - spot->values[i]) / spot->steps; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
// SYSTEM
|
|
|
|
// SYSTEM
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
@ -412,13 +462,14 @@ void setup() { |
|
|
|
Serial.begin(9600); |
|
|
|
Serial.begin(9600); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
#ifdef __AVR_ATmega32U4__ |
|
|
|
#ifdef __AVR_ATmega32U4__ |
|
|
|
while (!Serial) { |
|
|
|
for (uint8_t i = 0; i <= 10; i++) { |
|
|
|
; // wait for serial port to connect. Needed for Leonardo only
|
|
|
|
if (!Serial) |
|
|
|
|
|
|
|
delay(100); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.println(F("<setup begin>")); |
|
|
|
Serial.println(F("<setup begin>")); |
|
|
@ -453,6 +504,10 @@ void setup() { |
|
|
|
// DMX setup
|
|
|
|
// DMX setup
|
|
|
|
spot[0].address = 1; |
|
|
|
spot[0].address = 1; |
|
|
|
spot[1].address = 5; |
|
|
|
spot[1].address = 5; |
|
|
|
|
|
|
|
/* spot[2].address = 10;
|
|
|
|
|
|
|
|
spot[3].address = 14; |
|
|
|
|
|
|
|
spot[4].address = 17; |
|
|
|
|
|
|
|
spot[5].address = 20; */ |
|
|
|
|
|
|
|
|
|
|
|
// setup audio card
|
|
|
|
// setup audio card
|
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
@ -485,7 +540,7 @@ void setup() { |
|
|
|
// init schedular
|
|
|
|
// init schedular
|
|
|
|
sched.addJob(button_check, SENSOR_SCHED); |
|
|
|
sched.addJob(button_check, SENSOR_SCHED); |
|
|
|
sched.addJob(level_check, LEVEL_CHECK_SCHED); |
|
|
|
sched.addJob(level_check, LEVEL_CHECK_SCHED); |
|
|
|
sched.addJob(worker, WORKER_SCHED); |
|
|
|
sched.addJob(dmx_auto_colorchanger, DMX_COLOR_CHANGER_SCHED); |
|
|
|
sched.addJob(show_led, LED_SCHED); |
|
|
|
sched.addJob(show_led, LED_SCHED); |
|
|
|
//sched.addJob(test_worker, 1000);
|
|
|
|
//sched.addJob(test_worker, 1000);
|
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|