From 7dc5950b6a2ed68c98fdce5c623e11f5bde47d46 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Tue, 15 Aug 2023 16:18:00 +0200 Subject: [PATCH] optimised DLED stability --- LinuxCNC_ArduinoConnector.ino | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/LinuxCNC_ArduinoConnector.ino b/LinuxCNC_ArduinoConnector.ino index dd1c635..aa1e519 100644 --- a/LinuxCNC_ArduinoConnector.ino +++ b/LinuxCNC_ArduinoConnector.ino @@ -221,7 +221,7 @@ If you want the LED to be off just define {0,0,0}, . If you use STATUSLED, it will also take the colors of your definition here. */ -//#define DLED +#define DLED #ifdef DLED #include @@ -322,8 +322,11 @@ const int debounceDelay = 50; long EncCount[QuadEncs]; long OldEncCount[QuadEncs]; #endif -#ifdef JOYSTICK +#ifdef DLED + int DLEDstate[DLEDcount]; +#endif +#ifdef JOYSTICK long counter[JoySticks*2] = {0}; // Initialize an array for the counters long prevCounter[JoySticks*2] = {0}; // Initialize an array for the previous counters float incrementFactor[JoySticks*2] = {0.0}; // Initialize an array for the incrementFactors @@ -460,8 +463,26 @@ void loop() { #ifdef JOYSTICK readJoySticks(); //read Encoders & send data #endif + +#ifdef DLED + updateDLEDs(); //read Encoders & send data +#endif + } +#ifdef DLED +void updateDLEDs(){ + for(int i = 0; i< DLEDcount; i++){ + controlDLED(i, DLEDstate[i]); + //update all DLEDs regulary + } + + +} + +#endif + + #ifdef JOYSTICK void readJoySticks() { @@ -590,7 +611,8 @@ void StatLedErr(int offtime, int ontime){ if (newMillis - oldmillis >= offtime){ #ifdef DLED - controlDLED(StatLedPin, 1); + if(DLEDSTATUSLED == 1){ + controlDLED(StatLedPin, 1);} #endif #ifndef DLED digitalWrite(StatLedPin, HIGH); @@ -598,7 +620,8 @@ void StatLedErr(int offtime, int ontime){ } if (newMillis - oldmillis >= offtime+ontime){{ #ifdef DLED - controlDLED(StatLedPin, 0); + if(DLEDSTATUSLED == 1){ + controlDLED(StatLedPin, 0);} #endif #ifndef DLED digitalWrite(StatLedPin, LOW); @@ -640,6 +663,7 @@ void initDLED(){ void controlDLED(int Pin, int Stat){ if(Stat == 1){ + strip.setPixelColor(Pin, strip.Color(DledOnColors[Pin][0],DledOnColors[Pin][1],DledOnColors[Pin][2])); #ifdef DEBUG Serial.print("DLED No."); @@ -650,6 +674,7 @@ void controlDLED(int Pin, int Stat){ #endif } else{ + strip.setPixelColor(Pin, strip.Color(DledOffColors[Pin][0],DledOffColors[Pin][1],DledOffColors[Pin][2])); #ifdef DEBUG Serial.print("DLED No."); @@ -805,6 +830,7 @@ void commandReceived(char cmd, uint16_t io, uint16_t value){ #endif #ifdef DLED if(cmd == 'D'){ + DLEDstate[io] = value; controlDLED(io,value); lastcom=millis();