From 4659e8a8cd2d94faeeaa368a290ff4d171ac8c94 Mon Sep 17 00:00:00 2001 From: jyanev <74617990+jyanev@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:40:19 -0500 Subject: [PATCH 1/2] Completes #47 (#73) * allow setting led color via hex value * set controller endpoint for setting RGB via hex * fixed spacing error in url for hex converter with frequencies --------- Co-authored-by: Adrian Swindle --- .../components/controllers/rgbController.java | 11 ++++++++++ .../outputdevices/RGBLEDHelper.java | 21 ++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/rgbController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/rgbController.java index 5cbe964c..11b635e7 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/rgbController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/rgbController.java @@ -62,6 +62,17 @@ public void setColor(int redVal, int greenVal, int blueVal, int frequency1, int rgbledHelper.setColor(colors, frequency); } + @Get("/setColorHex/{hexValue}") + public void setColorHex(String hexValue) { + rgbledHelper.setColorHex(hexValue); + } + + @Get("/setColorHex/{hexValue},{frequency1},{frequency2},{frequency3}") + public void setColorHex(String hexValue, int frequency1, int frequency2, int frequency3) { + int[] frequency = new int[] {frequency1, frequency2, frequency3}; + rgbledHelper.setColorHex(hexValue, frequency); + } + @Get("/ledOff") public void ledOff() { rgbledHelper.ledOff(); diff --git a/micronautpi4j-utils/src/main/java/com/opensourcewithslu/outputdevices/RGBLEDHelper.java b/micronautpi4j-utils/src/main/java/com/opensourcewithslu/outputdevices/RGBLEDHelper.java index b3052288..ec6dad00 100644 --- a/micronautpi4j-utils/src/main/java/com/opensourcewithslu/outputdevices/RGBLEDHelper.java +++ b/micronautpi4j-utils/src/main/java/com/opensourcewithslu/outputdevices/RGBLEDHelper.java @@ -47,12 +47,27 @@ public void setColor(int[] colors, int[] frequency) public void setColorHex(String hex) { log.trace("setting the color via hex"); - //input the hex splitting and frequency stuff + // hex splitting into rbg int values + int r = (Integer.decode(hex) & 0xFF0000) >> 16; + int g = (Integer.decode(hex) & 0xFF00) >> 8; + int b = (Integer.decode(hex) & 0xFF); + + // no frequency input, default value 50 + red.on(r, 50); + green.on(g, 50); + blue.on(b, 50); } - public void setColorHex(String hex, int frequency) { + public void setColorHex(String hex, int[] frequency) { log.trace("setting the color and frequency via hex and int"); - // input the hex splitting and frequency stuff + // hex splitting into rbg int values + int r = (Integer.decode(hex) & 0xFF0000) >> 16; + int g = (Integer.decode(hex) & 0xFF00) >> 8; + int b = (Integer.decode(hex) & 0xFF); + + red.on(r, frequency[0]); + green.on(g, frequency[1]); + blue.on(b, frequency[2]); } //tag::method[] From 1291e9c04ddbdb1955e7d06c740d1d90ce13d866 Mon Sep 17 00:00:00 2001 From: Joe Folen <96354144+joefol@users.noreply.github.com> Date: Sun, 15 Oct 2023 21:56:54 -0500 Subject: [PATCH 2/2] Added documentation for RGB LED circuit guide. Issue 74 (#79) * Added location for RGB LED circuit guide. * Added diagrams and link for hardware setup * Addresses requested changes * Changed default frequency to 200 --------- Co-authored-by: ruthvikm --- .../components/outputComponents/rgbLed.adoc | 58 ++++++++++++++++++- .../outputdevices/RGBLEDHelper.java | 37 +++++++----- 2 files changed, 78 insertions(+), 17 deletions(-) diff --git a/micronautpi4j-utils/src/docs/asciidoc/components/outputComponents/rgbLed.adoc b/micronautpi4j-utils/src/docs/asciidoc/components/outputComponents/rgbLed.adoc index 0e98139d..1e27de4f 100644 --- a/micronautpi4j-utils/src/docs/asciidoc/components/outputComponents/rgbLed.adoc +++ b/micronautpi4j-utils/src/docs/asciidoc/components/outputComponents/rgbLed.adoc @@ -1,7 +1,63 @@ -==== RGB LED +== RGB LED [.text-right] https://github.com/oss-slu/Pi4Micronaut/edit/develop/micronautpi4j-utils/src/docs/asciidoc/components/outputComponents/rgbLed.adoc[Improve this doc] +===== Overview +This document provides details of the RGB (Red-Green-Blue) LED circuit, +including its components, assembly instructions, and functionality. + +===== Components +. RGB LED +. 3 x 220Ω resistors (for current limiting) +. Breadboard +. Jumper wires +. Power source (appropriate voltage, typically 3.3V or 5V) + +===== Assembly Instructions +. Place the RGB LED on the Breadboard. The LED has four pins - one for each of the +colors (Red, Green, and Blue) and one common pin (either cathode or anode). +. Connect the Resistors. Attach a 220Ω resistor to each of the RGB pins of the LED. +This is to limit the current and protect the LED. +. Power Connections: +** If using a common cathode RGB LED, connect the common pin directly to the +ground (GND) and the other ends of the resistors to the respective positive +terminals (like GPIO pins of a microcontroller or direct power source). +** If using a common anode RGB LED, connect the common pin directly to the +positive voltage source (VCC) and the other ends of the resistors to the respective +negative terminals (like GPIO pins set to OUTPUT and LOW on a microcontroller). + +===== Circuit Diagram +Model: + +image::https://docs.sunfounder.com/projects/raphael-kit/en/latest/_images/image61.png[] + +Circuit Diagram: + +image::https://docs.sunfounder.com/projects/raphael-kit/en/latest/_images/rgb_led_schematic.png[] + +===== Functionality +The RGB LED can produce a wide range of colors by mixing different intensities of +Red, Green, and Blue. By adjusting the power to each pin, various colors can be +produced. For instance: + +* Red: Power the Red pin while keeping Green and Blue off. +* Green: Power the Green pin while keeping Red and Blue off. +* Blue: Power the Blue pin while keeping Red and Green off. +* Yellow: Power both Red and Green pins while keeping Blue off. +* Cyan: Power both Green and Blue pins while keeping Red off. +* Magenta: Power both Red and Blue pins while keeping Green off. +* White: Power all three pins + +===== Troubleshooting +. LED not lighting up: Check all connections, ensure the LED is placed correctly, +and check the power source. +. Only one color is working: One of the pins might have a loose connection. Verify +each color pin's connection. +. LED is too dim: The resistor value might be too high. Ensure you're using 220Ω or +adjust according to your power source and LED specifications + +===== Note: The Hex value format must start with "0x" not "#" while passing it as a parameter of "setColorHex()" method. For example, use "0x0000ff" for blue. + ===== YAML Pin Order The order for declaring pins for a RGB LED component in the application.yaml file is as follows diff --git a/micronautpi4j-utils/src/main/java/com/opensourcewithslu/outputdevices/RGBLEDHelper.java b/micronautpi4j-utils/src/main/java/com/opensourcewithslu/outputdevices/RGBLEDHelper.java index ec6dad00..6bd55fc9 100644 --- a/micronautpi4j-utils/src/main/java/com/opensourcewithslu/outputdevices/RGBLEDHelper.java +++ b/micronautpi4j-utils/src/main/java/com/opensourcewithslu/outputdevices/RGBLEDHelper.java @@ -30,9 +30,9 @@ public RGBLEDHelper(MultipinConfiguration pwm) public void setColor(int[] colors) //end::method[] { - red.on(colors[0], 50); - green.on(colors[1], 50); - blue.on(colors[2], 50); + red.on(colors[0], 200); + green.on(colors[1], 200); + blue.on(colors[2], 200); } //tag::method[] @@ -45,20 +45,25 @@ public void setColor(int[] colors, int[] frequency) blue.on(colors[2], frequency[2]); } - public void setColorHex(String hex) { + //tag::method[] + public void setColorHex(String hex) + //end::method[] + { log.trace("setting the color via hex"); // hex splitting into rbg int values int r = (Integer.decode(hex) & 0xFF0000) >> 16; int g = (Integer.decode(hex) & 0xFF00) >> 8; int b = (Integer.decode(hex) & 0xFF); - // no frequency input, default value 50 - red.on(r, 50); - green.on(g, 50); - blue.on(b, 50); + // no frequency input, default value 200 + red.on(r, 200); + green.on(g, 200); + blue.on(b, 200); } - - public void setColorHex(String hex, int[] frequency) { + //tag::method[] + public void setColorHex(String hex, int[] frequency) + //end::method[] + { log.trace("setting the color and frequency via hex and int"); // hex splitting into rbg int values int r = (Integer.decode(hex) & 0xFF0000) >> 16; @@ -75,7 +80,7 @@ public void setRed(int red) //end::method[] { log.trace("Set red"); - this.red.on(red, 50); + this.red.on(red, 200); } //tag::method[] @@ -91,7 +96,7 @@ public void setBlue(int blue) //end::method[] { log.trace("set blue"); - this.blue.on(blue, 50); + this.blue.on(blue, 200); } //tag::method[] @@ -107,7 +112,7 @@ public void setGreen(int green) //end::method[] { log.trace("set green"); - this.green.on(green, 50); + this.green.on(green, 200); } //tag::method[] @@ -132,8 +137,8 @@ public void ledOn() //end::method[] { log.trace("turning on each LED pin and setting to 100"); - this.red.on(100, 50); - this.green.on(100, 50); - this.blue.on(100, 50); + this.red.on(100, 200); + this.green.on(100, 200); + this.blue.on(100, 200); } }