diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 4610c4f945..a40b4f0c9b 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -1375,6 +1375,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 6e6c1d3813..4718b64e16 100755 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -113,7 +113,7 @@ * M108 - Break out of heating loops (M109, M190, M303). With no controller, breaks out of M0/M1. (Requires EMERGENCY_PARSER) * M109 - Sxxx Wait for extruder current temp to reach target temp. Waits only when heating * Rxxx Wait for extruder current temp to reach target temp. Waits when heating and cooling - * IF AUTOTEMP is enabled, S B F. Exit autotemp by any M109 without F + * If AUTOTEMP is enabled, S B F. Exit autotemp by any M109 without F * M110 - Set the current line number. (Used by host printing) * M111 - Set debug flags: "M111 S". See flag bits defined in enum.h. * M112 - Emergency stop. @@ -131,7 +131,7 @@ * M140 - Set bed target temp. S * M145 - Set heatup values for materials on the LCD. H B F for S (0=PLA, 1=ABS) * M149 - Set temperature units. (Requires TEMPERATURE_UNITS_SUPPORT) - * M150 - Set BlinkM Color R U B. Values 0-255. (Requires BLINKM) + * M150 - Set Status LED Color as R U B. Values 0-255. (Requires BLINKM or RGB_LED) * M155 - Auto-report temperatures with interval of S. (Requires AUTO_REPORT_TEMPERATURES) * M163 - Set a single proportion for a mixing extruder. (Requires MIXING_EXTRUDER) * M164 - Save the mix as a virtual extruder. (Requires MIXING_EXTRUDER and MIXING_VIRTUAL_TOOLS) @@ -5958,20 +5958,55 @@ inline void gcode_M121() { endstops.enable_globally(false); } } #endif // HAVE_TMC2130DRIVER -#if ENABLED(BLINKM) +#if ENABLED(BLINKM) || ENABLED(RGB_LED) + + void set_led_color(const uint8_t r, const uint8_t g, const uint8_t b) { + + #if ENABLED(BLINKM) + + // This variant uses i2c to send the RGB components to the device. + SendColors( + code_seen('R') ? code_value_byte() : 0, + code_seen('U') ? code_value_byte() : 0, + code_seen('B') ? code_value_byte() : 0 + ); + + #else + + // This variant uses 3 separate pins for the RGB components. + // If the pins can do PWM then their intensity will be set. + digitalWrite(RGB_LED_R_PIN, r ? HIGH : LOW); + digitalWrite(RGB_LED_G_PIN, g ? HIGH : LOW); + digitalWrite(RGB_LED_B_PIN, b ? HIGH : LOW); + analogWrite(RGB_LED_R_PIN, r); + analogWrite(RGB_LED_G_PIN, g); + analogWrite(RGB_LED_B_PIN, b); + + #endif + } /** * M150: Set Status LED Color - Use R-U-B for R-G-B + * + * Always sets all 3 components. If a component is left out, set to 0. + * + * Examples: + * + * M150 R255 ; Turn LED red + * M150 R255 U127 ; Turn LED orange (PWM only) + * M150 ; Turn LED off + * M150 R U B ; Turn LED white + * */ inline void gcode_M150() { - SendColors( - code_seen('R') ? code_value_byte() : 0, - code_seen('U') ? code_value_byte() : 0, - code_seen('B') ? code_value_byte() : 0 + set_led_color( + code_seen('R') ? (code_has_value() ? code_value_byte() : 255) : 0, + code_seen('U') ? (code_has_value() ? code_value_byte() : 255) : 0, + code_seen('B') ? (code_has_value() ? code_value_byte() : 255) : 0 ); } -#endif // BLINKM +#endif // BLINKM || RGB_LED /** * M200: Set filament diameter and set E axis units to cubic units @@ -8147,9 +8182,9 @@ void process_next_command() { break; #endif - #if ENABLED(BLINKM) + #if ENABLED(BLINKM) || ENABLED(RGB_LED) - case 150: // M150: Set the BlinkM LCD color + case 150: // M150: Set Status LED Color gcode_M150(); break; @@ -10071,6 +10106,12 @@ void setup() { OUT_WRITE(STAT_LED_BLUE_PIN, LOW); // turn it off #endif + #if ENABLED(RGB_LED) + pinMode(RGB_LED_R_PIN, OUTPUT); + pinMode(RGB_LED_G_PIN, OUTPUT); + pinMode(RGB_LED_B_PIN, OUTPUT); + #endif + lcd_init(); #if ENABLED(SHOW_BOOTSCREEN) #if ENABLED(DOGLCD) diff --git a/Marlin/SanityCheck.h b/Marlin/SanityCheck.h index ebb1008002..0431a820f0 100644 --- a/Marlin/SanityCheck.h +++ b/Marlin/SanityCheck.h @@ -885,6 +885,17 @@ #endif #endif +/** + * RGB_LED Requirements + */ +#if ENABLED(RGB_LED) + #if !(PIN_EXISTS(RGB_LED_R) && PIN_EXISTS(RGB_LED_G) && PIN_EXISTS(RGB_LED_B)) + #error "RGB_LED requires RGB_LED_R_PIN, RGB_LED_G_PIN, and RGB_LED_B_PIN." + #elif ENABLED(BLINKM) + #error "RGB_LED and BLINKM are currently incompatible (both use M150)." + #endif +#endif + /** * Auto Fan check for PWM pins */ diff --git a/Marlin/example_configurations/Cartesio/Configuration.h b/Marlin/example_configurations/Cartesio/Configuration.h index 6ba809172c..36c15834bc 100644 --- a/Marlin/example_configurations/Cartesio/Configuration.h +++ b/Marlin/example_configurations/Cartesio/Configuration.h @@ -1375,6 +1375,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h index bde82b2931..d0d59234d9 100644 --- a/Marlin/example_configurations/Felix/Configuration.h +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -1358,6 +1358,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/Felix/DUAL/Configuration.h b/Marlin/example_configurations/Felix/DUAL/Configuration.h index e4f92618bd..df88bcdd3d 100644 --- a/Marlin/example_configurations/Felix/DUAL/Configuration.h +++ b/Marlin/example_configurations/Felix/DUAL/Configuration.h @@ -1358,6 +1358,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/Hephestos/Configuration.h b/Marlin/example_configurations/Hephestos/Configuration.h index 3d033f95c0..64b55bc184 100644 --- a/Marlin/example_configurations/Hephestos/Configuration.h +++ b/Marlin/example_configurations/Hephestos/Configuration.h @@ -1367,6 +1367,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/Hephestos_2/Configuration.h b/Marlin/example_configurations/Hephestos_2/Configuration.h index 79a797df58..3cee282c8a 100644 --- a/Marlin/example_configurations/Hephestos_2/Configuration.h +++ b/Marlin/example_configurations/Hephestos_2/Configuration.h @@ -1369,6 +1369,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/K8200/Configuration.h b/Marlin/example_configurations/K8200/Configuration.h index ec46a33fa2..648dfee469 100644 --- a/Marlin/example_configurations/K8200/Configuration.h +++ b/Marlin/example_configurations/K8200/Configuration.h @@ -1409,6 +1409,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/K8400/Configuration.h b/Marlin/example_configurations/K8400/Configuration.h index 35ae51196c..e90c23357a 100644 --- a/Marlin/example_configurations/K8400/Configuration.h +++ b/Marlin/example_configurations/K8400/Configuration.h @@ -1375,6 +1375,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/K8400/Dual-head/Configuration.h b/Marlin/example_configurations/K8400/Dual-head/Configuration.h index 5d1c84c45c..41103c2605 100644 --- a/Marlin/example_configurations/K8400/Dual-head/Configuration.h +++ b/Marlin/example_configurations/K8400/Dual-head/Configuration.h @@ -1375,6 +1375,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h b/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h index bc96cb8820..ef14cbc117 100644 --- a/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h +++ b/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h @@ -1375,6 +1375,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/RigidBot/Configuration.h b/Marlin/example_configurations/RigidBot/Configuration.h index d1c2334e70..890f19817e 100644 --- a/Marlin/example_configurations/RigidBot/Configuration.h +++ b/Marlin/example_configurations/RigidBot/Configuration.h @@ -1375,6 +1375,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/SCARA/Configuration.h b/Marlin/example_configurations/SCARA/Configuration.h index 6f72476cbf..dedce05756 100644 --- a/Marlin/example_configurations/SCARA/Configuration.h +++ b/Marlin/example_configurations/SCARA/Configuration.h @@ -1390,6 +1390,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/TAZ4/Configuration.h b/Marlin/example_configurations/TAZ4/Configuration.h index 6f4afcf377..c9ff7725d4 100644 --- a/Marlin/example_configurations/TAZ4/Configuration.h +++ b/Marlin/example_configurations/TAZ4/Configuration.h @@ -1396,6 +1396,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/WITBOX/Configuration.h b/Marlin/example_configurations/WITBOX/Configuration.h index fc5f81503a..3ddab0316e 100644 --- a/Marlin/example_configurations/WITBOX/Configuration.h +++ b/Marlin/example_configurations/WITBOX/Configuration.h @@ -1367,6 +1367,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/adafruit/ST7565/Configuration.h b/Marlin/example_configurations/adafruit/ST7565/Configuration.h index aa2079865c..1450fdba63 100644 --- a/Marlin/example_configurations/adafruit/ST7565/Configuration.h +++ b/Marlin/example_configurations/adafruit/ST7565/Configuration.h @@ -1375,6 +1375,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/delta/biv2.5/Configuration.h b/Marlin/example_configurations/delta/biv2.5/Configuration.h index 93b8c99499..21dee19881 100644 --- a/Marlin/example_configurations/delta/biv2.5/Configuration.h +++ b/Marlin/example_configurations/delta/biv2.5/Configuration.h @@ -1471,6 +1471,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/delta/generic/Configuration.h b/Marlin/example_configurations/delta/generic/Configuration.h index 38ac08962c..412163d8be 100644 --- a/Marlin/example_configurations/delta/generic/Configuration.h +++ b/Marlin/example_configurations/delta/generic/Configuration.h @@ -1465,6 +1465,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/delta/kossel_mini/Configuration.h b/Marlin/example_configurations/delta/kossel_mini/Configuration.h index a6d187cdf1..4c1e1f1173 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration.h @@ -1468,6 +1468,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/delta/kossel_pro/Configuration.h b/Marlin/example_configurations/delta/kossel_pro/Configuration.h index ee5cbd1e21..27f396d4d4 100644 --- a/Marlin/example_configurations/delta/kossel_pro/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_pro/Configuration.h @@ -1467,6 +1467,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/delta/kossel_xl/Configuration.h b/Marlin/example_configurations/delta/kossel_xl/Configuration.h index 619cab9311..662550bfeb 100644 --- a/Marlin/example_configurations/delta/kossel_xl/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_xl/Configuration.h @@ -1471,6 +1471,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/makibox/Configuration.h b/Marlin/example_configurations/makibox/Configuration.h index d2e402cb7a..44e1a5fc23 100644 --- a/Marlin/example_configurations/makibox/Configuration.h +++ b/Marlin/example_configurations/makibox/Configuration.h @@ -1378,6 +1378,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/example_configurations/tvrrug/Round2/Configuration.h b/Marlin/example_configurations/tvrrug/Round2/Configuration.h index 48e777a754..13a102ae06 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration.h @@ -1371,6 +1371,14 @@ //define BlinkM/CyzRgb Support //#define BLINKM +// Support for an RGB LED using 3 separate pins with optional PWM +//#define RGB_LED +#if ENABLED(RGB_LED) + #define RGB_LED_R_PIN 34 + #define RGB_LED_G_PIN 43 + #define RGB_LED_B_PIN 35 +#endif + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas