# Spark rgb led --\> outside

**URL:** <https://community.particle.io/t/spark-rgb-led-outside/6331>\
**Category:** Firmware\
**Created:** [August 11, 2014, 8:23pm UTC](https://community.particle.io/t/spark-rgb-led-outside/6331 "2014-08-11T20:23:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![itayd100](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/itayd100/32/3031_2.png) [@itayd100](https://community.particle.io/u/itayd100)\
**Post date:** [August 11, 2014, 8:23pm UTC](https://community.particle.io/t/spark-rgb-led-outside/6331/1 "2014-08-11T20:23:52Z")

</div>

Hey,

I want to “copy” the Spark RGB LED outside of the board to mine RGB LED with the Analog out pins.

How can I do this? Do I need common anode/cathode LED?

Thanks,  
Itay

---

<div class="post-metadata">

**Author:** ![mumblepins](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mumblepins/32/3857_2.png) [@mumblepins](https://community.particle.io/u/mumblepins)\
**Post date:** [August 11, 2014, 9:00pm UTC](https://community.particle.io/t/spark-rgb-led-outside/6331/2 "2014-08-11T21:00:53Z")

</div>

Well, let’s take [this LED](https://www.sparkfun.com/products/105) as an example, seeing as how it seems to be well documented, and it already has a handy [diagram](http://wiring.org.co/learning/basics/rgbled.html). It’s a common cathode LED, but we could use a common anode LED the same way, the only difference is what way it’s wired up. See this [diagram for example.](http://dmsp.digital.eca.ed.ac.uk/blog/actionsound/files/2013/04/rgbled.jpg)

Now, differences from the diagram are that the Spark has ‘analog’ PWM output on pins A0, A1, A4, A5, A6, A7, D0 and D1. So, choose 3 pins for our output. Also, I believe that that circuit is intended to be driven by 5V outputs, whereas the Spark runs at 3.3V. No worries, we’ll use [this handy calculator](http://led.linear1.org/1led.wiz) to figure out the proper size resistors for the LEDs. I say LEDs, because really a tricolor LED is just 3 LEDs in one package.

If we look at the [datasheet](https://www.sparkfun.com/datasheets/Components/YSL-R596CR3G4B5C-C10.pdf) we find that the LEDs all require 20 mA of current, and the forward voltage is 2, 3.2, and 3.2V for the RGB parts respectively. So we plug our numbers in to the calculator, we find that we need one 68 ohm resistor for the red part, and a 5.6 ohm resistor for the other two parts. So, wire as shown in the wiring diagram, substituting the found resistances.

As far as coding goes, the code found in the sample is practically ready for the Spark already, with just minor changes to the pin numbers (I chose A5,A6,A7):

```
int REDPin = A5; // RED pin of the LED to PWM pin **A5**
int GREENPin = A6; // GREEN pin of the LED to PWM pin **A6**
int BLUEPin = A7; // BLUE pin of the LED to PWM pin **A7**
int brightness = 0; // LED brightness
int increment = 5; // brightness increment
void setup()
{
  pinMode(REDPin, OUTPUT);
  pinMode(GREENPin, OUTPUT);
  pinMode(BLUEPin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  brightness = brightness + increment; // increment brightness for next loop iteration

  if (brightness <= 0 || brightness >= 255) // reverse the direction of the fading
  {
    increment = -increment;
  }
  brightness = constrain(brightness, 0, 255);
  analogWrite(REDPin, brightness);
  analogWrite(GREENPin, brightness);
  analogWrite(BLUEPin, brightness);

  delay(20); // wait for 20 milliseconds to see the dimming effect
}

```

---

<div class="post-metadata">

**Author:** ![itayd100](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/itayd100/32/3031_2.png) [@itayd100](https://community.particle.io/u/itayd100)\
**Post date:** [August 11, 2014, 9:22pm UTC](https://community.particle.io/t/spark-rgb-led-outside/6331/3 "2014-08-11T21:22:55Z")

</div>

Hey @mumblepins,

Thanks for the answer, but I know how to do the PWM effect.

Maybe I wasn’t clear, I want to “take out”(or copy) the Spark RGB LED. I have a box, the spark core is placed inside and I want to see the “breathing LED” outside of the box. I want to connect my RGB LED to the Analog pins and make this behave like the spark core LED. I think it should be some parameter in the core firmware, some “inside IO pins”.

---

<div class="post-metadata">

**Author:** ![mumblepins](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mumblepins/32/3857_2.png) [@mumblepins](https://community.particle.io/u/mumblepins)\
**Post date:** [August 12, 2014, 1:26am UTC](https://community.particle.io/t/spark-rgb-led-outside/6331/4 "2014-08-12T01:26:50Z")

</div>

Ah, I misunderstood. Well, the easy solution is one of these: [http://www.mouser.com/Optoelectronics/LED-Indication/LED-Light-Pipes/\_/N-b1d20](http://www.mouser.com/Optoelectronics/LED-Indication/LED-Light-Pipes/_/N-b1d20)🙂

The less snarky answer is that the firmware would have to be modified, and possibly even the hardware. If you want to display your own status updates, you could probably make an alternate RGB library, and switch the core to manual control, and monitor and setup connection that way.

I ?think? that if you wanted to get down and dirty, you could probably change the TIM1 Pin output in [the firmware](https://github.com/spark/core-common-lib/blob/160e2dfc85047d3f01ea8139126f2c848d889bb1/SPARK_Firmware_Driver/src/hw_config.c#L564)  
to point to the CH1N, CH2N, and CH3N pins as opposed to the CH1, CH2, and CH3 pins. Those outputs are connected to the SPI pins, which correspond to A3, A4, and A5 respectively. Take all that with a very large grain of salt though, I don’t have a ton of experience with the firmware or the hardware behind it, so if you try it you might fry your core.

Refs:  
[http://read.pudn.com/downloads106/sourcecode/embed/437624/stm32/STM32F%20Documents/Application%20Note/STM32F10xxx%20TIM1%20application%20examples.pdf](http://read.pudn.com/downloads106/sourcecode/embed/437624/stm32/STM32F%20Documents/Application%20Note/STM32F10xxx%20TIM1%20application%20examples.pdf)

[https://github.com/spark/core/blob/master/Datasheets/Manuals/STM32F10X-reference-manual.pdf](https://github.com/spark/core/blob/master/Datasheets/Manuals/STM32F10X-reference-manual.pdf)

> **[particle-iot/core](https://github.com/particle-iot/core)**
>
> core - Hardware design files for the Spark Core, a tiny Wi-Fi development kit.

---

<div class="post-metadata">

**Author:** ![itayd100](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/itayd100/32/3031_2.png) [@itayd100](https://community.particle.io/u/itayd100)\
**Post date:** [August 17, 2014, 8:48pm UTC](https://community.particle.io/t/spark-rgb-led-outside/6331/5 "2014-08-17T20:48:19Z")

</div>

> [@mumblepins](#):
>
> point to the CH1N, CH2N, and CH3N pins as opposed to the CH1, CH2, and CH3 pins. Those outputs are connected to the SPI pins,

@mumblepins, It took me a while, but I looked inside the code. I saw what you mean with the "TIM" pins. The question is if I get the brightness of each TIM and send it to the Analog output. Did you see where they are sending the value of "breathing" LED or which VOID is handling it?

Thank you for your answer.

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [March 13, 2015, 5:41pm UTC](https://community.particle.io/t/spark-rgb-led-outside/6331/6 "2015-03-13T17:41:44Z")

</div>

I know this is an old thread, but someone asked me about this recently, so I wanted to suggest this solution:

```auto
extern uint32_t lastSignalColor;
extern uint32_t lastRGBColor;

//and you can break out the value with something like:
uint16_t ccr[3];
ccr[0] = ((lastSignalColor >>16) & 0xFF);
ccr[1] = ((lastSignalColor >>8) & 0xFF);
ccr[2] = (lastSignalColor & 0xFF);

```

Thanks,  
David
