Support for an RGB LED using 3 pins

This commit is contained in:
Scott Lahteine 2016-11-29 19:51:13 -06:00
parent 092e949b58
commit 65c50e062e
24 changed files with 238 additions and 10 deletions

View file

@ -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

View file

@ -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<mintemp> B<maxtemp> F<factor>. Exit autotemp by any M109 without F
* If AUTOTEMP is enabled, S<mintemp> B<maxtemp> F<factor>. Exit autotemp by any M109 without F
* M110 - Set the current line number. (Used by host printing)
* M111 - Set debug flags: "M111 S<flagbits>". See flag bits defined in enum.h.
* M112 - Emergency stop.
@ -131,7 +131,7 @@
* M140 - Set bed target temp. S<temp>
* M145 - Set heatup values for materials on the LCD. H<hotend> B<bed> F<fan speed> for S<material> (0=PLA, 1=ABS)
* M149 - Set temperature units. (Requires TEMPERATURE_UNITS_SUPPORT)
* M150 - Set BlinkM Color R<red> U<green> B<blue>. Values 0-255. (Requires BLINKM)
* M150 - Set Status LED Color as R<red> U<green> B<blue>. Values 0-255. (Requires BLINKM or RGB_LED)
* M155 - Auto-report temperatures with interval of S<seconds>. (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)

View file

@ -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
*/

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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