Several fixes and additions.

Switching light enabled.
Switching fog enabled.
main
Holger Wirtz 7 months ago
parent 89d2e3e29b
commit 2134a67312
  1. 154
      RiTCh_Lightshow.ino

@ -29,15 +29,22 @@
#define BUTTON_LONG_PRESS 1000 #define BUTTON_LONG_PRESS 1000
#define MIN_TIME_SWITCH_PRESSED 50 #define MIN_TIME_SWITCH_PRESSED 50
#define POTI_DEAD_ZONE 3
#define LED_NORMAL_BRIGHTNESS 180 #define LED_NORMAL_BRIGHTNESS 180
#define LED_PLAY_BRIGHTNESS 20 #define LED_PLAY_BRIGHTNESS 20
#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 MAX_DMX_SPOTS 2
#define DMX_FOG_MACHINE_ADDRESS 100
#define DMX_BRIGHTNESS 0
#define DMX_FADE_TIME 1
#define DMX_HOLD_TIME 2
#define DMX_FOG_LEVEL 3
#define MIN_DMX_FADE_TIME 1 #define MIN_DMX_FADE_TIME 1
#define MAX_DMX_FADE_TIME 3 #define MAX_DMX_FADE_TIME 10
#define MIN_DMX_HOLD_TIME 5 #define MIN_DMX_HOLD_TIME 5
#define MAX_DMX_HOLD_TIME 15 #define MAX_DMX_HOLD_TIME 15
@ -61,6 +68,14 @@ uint32_t button_time[4] = { 0, 0, 0, 0 };
uint8_t poti_level[4] = { 0, 0, 0, 0 }; uint8_t poti_level[4] = { 0, 0, 0, 0 };
uint8_t brightness = LED_NORMAL_BRIGHTNESS; uint8_t brightness = LED_NORMAL_BRIGHTNESS;
enum {
NORMAL,
WHITE,
OFF
};
bool fog_state = false;
uint8_t light_state = NORMAL;
typedef struct { typedef struct {
uint8_t dmx_type = 4; uint8_t dmx_type = 4;
uint16_t address = 0; uint16_t address = 0;
@ -115,7 +130,7 @@ void level_check(void) {
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
poti_lvl = map(analogRead(poti_pin_by_number(i)), 15, 1023, 0, 255); poti_lvl = map(analogRead(poti_pin_by_number(i)), 15, 1023, 0, 255);
if (poti_lvl != poti_level[i]) { if (poti_lvl < poti_level[i] - POTI_DEAD_ZONE || poti_lvl > poti_level[i] + POTI_DEAD_ZONE) {
poti_level[i] = poti_lvl; poti_level[i] = poti_lvl;
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Poti[")); Serial.print(F("Poti["));
@ -133,6 +148,11 @@ void show_led(void) {
} }
void worker(void) { void worker(void) {
// DMX auto Fade
if (light_state != NORMAL)
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;
@ -145,7 +165,8 @@ void worker(void) {
} }
if (diff_counter != 0) { if (diff_counter != 0) {
// start hold timer // start hold timer
spot[s].steps = random(MIN_DMX_HOLD_TIME, MIN_DMX_HOLD_TIME + ((MAX_DMX_HOLD_TIME - MIN_DMX_HOLD_TIME) * poti_level[2] / 255.0)) * 1000 / WORKER_SCHED; int8_t start = MIN_DMX_FADE_TIME + MIN_DMX_FADE_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 / WORKER_SCHED;
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Spot ")); Serial.print(F("Spot "));
Serial.print(s, DEC); Serial.print(s, DEC);
@ -157,9 +178,10 @@ void worker(void) {
// new random values // new random values
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;
spot[s].steps = random(MIN_DMX_FADE_TIME, MIN_DMX_FADE_TIME + ((MAX_DMX_FADE_TIME - MIN_DMX_FADE_TIME) * poti_level[1] / 255.0)) * 1000 / WORKER_SCHED; 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, random(0, 1024) / 1024.0, random(128, 255) / 255.0, rgb); color_converter.hsvToRgb(random(0, 1024) / 1024.0, 1.0, 1.0, rgb);
for (uint8_t i = 0; i < 3; i++) for (uint8_t i = 0; i < 3; i++)
spot[s].diff[i] = (rgb[i] - spot[s].values[i]) / spot[s].steps; spot[s].diff[i] = (rgb[i] - spot[s].values[i]) / spot[s].steps;
spot[s].diff[3] = (random(0, 128) - spot[3].values[3]) / 255.0; spot[s].diff[3] = (random(0, 128) - spot[3].values[3]) / 255.0;
@ -174,7 +196,7 @@ void worker(void) {
} 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]; spot[s].values[i] += spot[s].diff[i];
DmxSimple.write(spot[s].address + i, uint8_t(spot[s].values[i] * poti_level[0] / 255.0 + 0.5)); 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);
@ -191,6 +213,28 @@ void worker(void) {
} }
spot[s].steps--; spot[s].steps--;
} }
// Fog machine
if (fog_state == true) {
DmxSimple.write(DMX_FOG_MACHINE_ADDRESS, poti_level[DMX_FOG_LEVEL]);
} else {
DmxSimple.write(DMX_FOG_MACHINE_ADDRESS, 0);
}
}
void test_worker(void) {
uint8_t start = MIN_DMX_FADE_TIME + MIN_DMX_FADE_TIME * poti_level[1] / 255.0 * 4;
uint8_t fade_time = random(start, start + ((MAX_DMX_FADE_TIME - start) * poti_level[1] / 255.0));
Serial.print("start:");
Serial.println(start, DEC);
Serial.print("MAX_DMX_FADE_TIME");
Serial.println(MAX_DMX_FADE_TIME, DEC);
Serial.print("POTI1:");
Serial.println(poti_level[1], DEC);
Serial.print("POTI1/255:");
Serial.println(poti_level[1] / 255.0, 3);
Serial.print("Fade-Time:");
Serial.println(fade_time, DEC);
} }
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
@ -198,25 +242,105 @@ void worker(void) {
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
void do_level(uint8_t p) { void do_level(uint8_t p) {
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("LEVEL ")); Serial.print(F("POTI "));
Serial.println(p); Serial.print(p);
Serial.print(F(": "));
Serial.println(poti_level[p]);
#endif #endif
DmxSimple.write(1 + p, poti_level[p]); switch (p) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
#ifdef DEBUG
Serial.print(F("Fog: "));
Serial.print(poti_level[DMX_FOG_LEVEL] / 255.0 * 100.0);
Serial.println(F("%"));
#endif
break;
}
} }
void do_button_long(uint8_t b) { void do_button_long(uint8_t b) {
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("LONG ")); Serial.print(F("BUTTON "));
Serial.print(b);
Serial.println(F(" LONG"));
#endif #endif
Serial.println(b);
switch (b) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
} }
void do_button_short(uint8_t b) { void do_button_short(uint8_t b) {
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("SHORT ")); Serial.print(F("BUTTON "));
Serial.print(b);
Serial.println(F(" SHORT"));
#endif
switch (b) {
case 0:
if (light_state == OFF || light_state == WHITE) {
#ifdef DEBUG
Serial.println(F("Light: NORMAL"));
#endif
light_state = NORMAL;
} else {
#ifdef DEBUG
Serial.println(F("Light: OFF"));
#endif
light_state = OFF;
}
break;
case 1:
if (light_state == OFF || light_state == NORMAL) {
#ifdef DEBUG
Serial.println(F("Light: WHITE"));
#endif
light_state = WHITE;
for (uint8_t s = 0; s < MAX_DMX_SPOTS; s++) {
for (uint8_t i = 0; i < spot[s].dmx_type; i++)
DmxSimple.write(spot[s].address + i, 255);
}
} else {
#ifdef DEBUG
Serial.println(F("Light: OFF"));
#endif
light_state = OFF;
}
break;
case 2:
break;
case 3:
fog_state = !fog_state;
#ifdef DEBUG
if (fog_state)
Serial.println(F("Fog: ON"));
else
Serial.println(F("Fog: OFF"));
#endif #endif
Serial.println(b); break;
}
if (light_state == OFF) {
for (uint8_t s = 0; s < MAX_DMX_SPOTS; s++) {
for (uint8_t i = 0; i < spot[s].dmx_type; i++)
DmxSimple.write(spot[s].address + i, 0);
}
}
} }
uint32_t button(byte button_nr) { uint32_t button(byte button_nr) {
@ -288,11 +412,14 @@ void setup() {
Serial.begin(9600); Serial.begin(9600);
#endif #endif
/*
#ifdef __AVR_ATmega32U4__ #ifdef __AVR_ATmega32U4__
while (!Serial) { while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only ; // wait for serial port to connect. Needed for Leonardo only
} }
#endif #endif
*/
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("<setup begin>")); Serial.println(F("<setup begin>"));
#endif #endif
@ -360,6 +487,7 @@ void setup() {
sched.addJob(level_check, LEVEL_CHECK_SCHED); sched.addJob(level_check, LEVEL_CHECK_SCHED);
sched.addJob(worker, WORKER_SCHED); sched.addJob(worker, WORKER_SCHED);
sched.addJob(show_led, LED_SCHED); sched.addJob(show_led, LED_SCHED);
//sched.addJob(test_worker, 1000);
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("<setup end>")); Serial.println(F("<setup end>"));
#endif #endif

Loading…
Cancel
Save