From 2143187b1224db0c664d03b1033f739241a3ec60 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 4 Apr 2024 12:50:05 +0200 Subject: [PATCH] Some changes for light level. --- RiTCh_Lightshow.ino | 68 +++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/RiTCh_Lightshow.ino b/RiTCh_Lightshow.ino index e6b84d4..211f106 100644 --- a/RiTCh_Lightshow.ino +++ b/RiTCh_Lightshow.ino @@ -19,16 +19,16 @@ #include "looper.h" #include -#define DEBUG 1 +//#define DEBUG 1 #define SENSOR_SCHED 10 -#define DMX_COLOR_CHANGER_SCHED 100 +#define DMX_COLOR_CHANGER_SCHED 50 #define LED_SCHED 50 -#define LEVEL_CHECK_SCHED 100 +#define LEVEL_CHECK_SCHED 50 #define DEBUG_SCHED 500 #define BUTTON_LONG_PRESS 1000 -#define MIN_TIME_SWITCH_PRESSED 50 +#define MIN_TIME_SWITCH_PRESSED 30 #define POTI_DEAD_ZONE 3 #define LED_NORMAL_BRIGHTNESS 180 #define LED_PLAY_BRIGHTNESS 20 @@ -36,7 +36,7 @@ #define MAX_VOL_LEVEL 30 #define MAX_DMX_LEVEL 255 #define DMX_FOG_MACHINE_ADDRESS 100 -#define MAX_RAND_WHITE_LEVEL 128 +#define MAX_RAND_WHITE_LEVEL 150 #define DMX_BRIGHTNESS 0 #define DMX_FADE_TIME 1 @@ -47,7 +47,7 @@ #define MAX_DMX_FADE_TIME 15 #define MIN_DMX_HOLD_TIME 3 #define MAX_DMX_HOLD_TIME 30 -#define ON_OFF_FADE_TIME 1 +#define ON_OFF_FADE_TIME 1.5 // Arduino pins #define POTI1_PIN A1 @@ -75,7 +75,7 @@ enum { OFF }; bool fog_state = false; -uint8_t light_state = NORMAL; +uint8_t light_state = OFF; typedef struct { uint8_t dmx_type = 4; @@ -152,10 +152,6 @@ void show_led(void) { void dmx_auto_colorchanger(void) { // DMX auto Fade - - //if (light_state != NORMAL) - // return; - for (uint8_t s = 0; s < MAX_DMX_SPOTS; s++) { uint8_t diff_counter = 0; @@ -170,7 +166,7 @@ void dmx_auto_colorchanger(void) { // start hold timer if (light_state != NORMAL) continue; - int8_t start = MIN_DMX_HOLD_TIME + MIN_DMX_HOLD_TIME * poti_level[1] / 255.0 * 4; + int8_t start = MIN_DMX_HOLD_TIME + MIN_DMX_HOLD_TIME * poti_level[DMX_HOLD_TIME] / 255.0 * MIN_DMX_HOLD_TIME; 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 Serial.print(F("Spot ")); @@ -185,7 +181,7 @@ void dmx_auto_colorchanger(void) { continue; RGBConverter color_converter; uint8_t rgb[3]; - uint8_t start = MIN_DMX_FADE_TIME + MIN_DMX_FADE_TIME * poti_level[2] / 255.0 * 4; + uint8_t start = MIN_DMX_FADE_TIME + MIN_DMX_FADE_TIME * poti_level[DMX_FADE_TIME] / 255.0 * MIN_DMX_FADE_TIME; color_converter.hsvToRgb(random(0, 1024) / 1024.0, 1.0, 1.0, rgb); @@ -212,7 +208,7 @@ void dmx_auto_colorchanger(void) { Serial.println(F(" seconds")); #endif } - } else { + } /* else { for (uint8_t i = 0; i < spot[s].dmx_type; i++) { if (spot[s].diff[i] != 0.0) { spot[s].values[i] += spot[s].diff[i]; @@ -224,7 +220,6 @@ void dmx_auto_colorchanger(void) { DmxSimple.write(spot[s].address + i, uint8_t(spot[s].values[i] * poti_level[DMX_BRIGHTNESS] / 255.0 + 0.5)); } - #ifdef DEBUG Serial.print(F("Spot ")); Serial.print(s, DEC); @@ -237,12 +232,13 @@ void dmx_auto_colorchanger(void) { Serial.print(F(" value ")); Serial.println(spot[s].values[i], 4); #endif - } - } + }*/ spot[s].steps--; } + dmx_commit(); + // Fog machine if (fog_state == true) { DmxSimple.write(DMX_FOG_MACHINE_ADDRESS, poti_level[DMX_FOG_LEVEL]); @@ -269,6 +265,24 @@ void test_worker(void) { //-------------------------------------------------------------------------------- // HELPER FUNCTIONS //-------------------------------------------------------------------------------- +void dmx_commit(void) { + float l = pow(poti_level[DMX_BRIGHTNESS] / 255.0, 3); + + for (uint8_t s = 0; s < MAX_DMX_SPOTS; s++) { + for (uint8_t i = 0; i < spot[s].dmx_type; i++) { + //if (spot[s].diff[i] != 0.0) { + 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] * l + 0.5)); + } + // } + } +} + void do_level(uint8_t p) { #ifdef DEBUG Serial.print(F("POTI ")); @@ -442,13 +456,13 @@ uint8_t poti_pin_by_number(byte n) { return (0); } -void set_rgbw(dmx_spot* spot, uint8_t fade, uint8_t* rgb, uint8_t w) { +void set_rgbw(dmx_spot* spot, float 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) { +void set_rgb(dmx_spot* spot, float 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; @@ -502,14 +516,14 @@ void setup() { DmxSimple.maxChannel(DMX_MAX_CHANNEL); // DMX setup - spot[0].address = 1; // Stairville LED Par56 MKII RGBA 10mm SI https://images.thomann.de/pics/atg/atgdata/document/manual/274646_c_274644_274646_375069_v3_de_online.pdf - spot[1].address = 5; // Stairville LED Par56 MKII RGBA 10mm SI - DmxSimple.write(9,0); // Init PAR64, channel: 9, DIP 1: on, DIP 4: on, DIP 8: off - spot[2].address = 10; // Stairville PAR 64 https://images.thomann.de/pics/atg/atgdata/document/manual/c_193245_v2_r3_de_online.pdf - DmxSimple.write(15,41); // Init LED Bar for 3-segment-mode, channel: 15 - spot[3].address = 17; // Stairville LED BAR RGB 252 - Segment 1 https://images.thomann.de/pics/prod/255346_manual.pdf - spot[4].address = 20; // Stairville LED BAR RGB 252 - Segment 2 - spot[5].address = 23; // Stairville LED BAR RGB 252 - Segment 3 + spot[0].address = 1; // Stairville LED Par56 MKII RGBA 10mm SI https://images.thomann.de/pics/atg/atgdata/document/manual/274646_c_274644_274646_375069_v3_de_online.pdf + spot[1].address = 5; // Stairville LED Par56 MKII RGBA 10mm SI + DmxSimple.write(9, 0); // Init PAR64, channel: 9, DIP 1: on, DIP 4: on, DIP 8: off + spot[2].address = 10; // Stairville PAR 64 https://images.thomann.de/pics/atg/atgdata/document/manual/c_193245_v2_r3_de_online.pdf + DmxSimple.write(15, 41); // Init LED Bar for 3-segment-mode, channel: 15 + spot[3].address = 17; // Stairville LED BAR RGB 252 - Segment 1 https://images.thomann.de/pics/prod/255346_manual.pdf + spot[4].address = 20; // Stairville LED BAR RGB 252 - Segment 2 + spot[5].address = 23; // Stairville LED BAR RGB 252 - Segment 3 // setup audio card #ifdef DEBUG