From 65c50e062e36703a7d0d303e979842eaea39c686 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 29 Nov 2016 19:51:13 -0600 Subject: [PATCH] Support for an RGB LED using 3 pins --- Marlin/Configuration.h | 8 +++ Marlin/Marlin_main.cpp | 61 ++++++++++++++++--- Marlin/SanityCheck.h | 11 ++++ .../Cartesio/Configuration.h | 8 +++ .../Felix/Configuration.h | 8 +++ .../Felix/DUAL/Configuration.h | 8 +++ .../Hephestos/Configuration.h | 8 +++ .../Hephestos_2/Configuration.h | 8 +++ .../K8200/Configuration.h | 8 +++ .../K8400/Configuration.h | 8 +++ .../K8400/Dual-head/Configuration.h | 8 +++ .../RepRapWorld/Megatronics/Configuration.h | 8 +++ .../RigidBot/Configuration.h | 8 +++ .../SCARA/Configuration.h | 8 +++ .../TAZ4/Configuration.h | 8 +++ .../WITBOX/Configuration.h | 8 +++ .../adafruit/ST7565/Configuration.h | 8 +++ .../delta/biv2.5/Configuration.h | 8 +++ .../delta/generic/Configuration.h | 8 +++ .../delta/kossel_mini/Configuration.h | 8 +++ .../delta/kossel_pro/Configuration.h | 8 +++ .../delta/kossel_xl/Configuration.h | 8 +++ .../makibox/Configuration.h | 8 +++ .../tvrrug/Round2/Configuration.h | 8 +++ 24 files changed, 238 insertions(+), 10 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 4610c4f94..a40b4f0c9 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 6e6c1d381..4718b64e1 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 ebb100800..0431a820f 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 6ba809172..36c15834b 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 bde82b293..d0d59234d 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 e4f92618b..df88bcdd3 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 3d033f95c..64b55bc18 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 79a797df5..3cee282c8 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 ec46a33fa..648dfee46 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 35ae51196..e90c23357 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 5d1c84c45..41103c260 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 bc96cb882..ef14cbc11 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 d1c2334e7..890f19817 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 6f72476cb..dedce0575 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 6f4afcf37..c9ff7725d 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 fc5f81503..3ddab0316 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 aa2079865..1450fdba6 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 93b8c9949..21dee1988 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 38ac08962..412163d8b 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 a6d187cdf..4c1e1f117 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 ee5cbd1e2..27f396d4d 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 619cab931..662550bfe 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 d2e402cb7..44e1a5fc2 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 48e777a75..13a102ae0 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