Skip to content

Commit

Permalink
Merging develop into main (#87)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>

---------

Co-authored-by: jyanev <[email protected]>
Co-authored-by: Adrian Swindle <[email protected]>
Co-authored-by: Joe Folen <[email protected]>
  • Loading branch information
4 people authored Oct 16, 2023
1 parent caa4298 commit 97e7551
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -45,22 +45,42 @@ 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");
//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 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");
// 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[]
public void setRed(int red)
//end::method[]
{
log.trace("Set red");
this.red.on(red, 50);
this.red.on(red, 200);
}

//tag::method[]
Expand All @@ -76,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[]
Expand All @@ -92,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[]
Expand All @@ -117,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);
}
}

0 comments on commit 97e7551

Please sign in to comment.