I need help getting Pure Data to control the colors of an RGB LED. I purchased this LED: https://www.ultimarc.com/arcade/buttons/classicrgb-led-pushbuttons/

Long term, my plan is to have with each button press of the arcade button, Pure Data chooses a color at random, and adjusts the color of the LED accordingly with each press.

But right now I'm stuck on getting Pure Data to control the LED at all.

The LED has four pins (gray, red, green, blue). If I plug the gray into 3.3v and each of the other pins into ground, the all the LEDs light up. Same thing if I plug the red, green, and blue pins into analog out 0,1,2. See the diagram here:

But how do I get Pure Data to change the color of the pins? Right now I'm just trying for the red pin and have green and blue unplugged.

Thank you.

    drumminhands LED has four pins (gray, red, green, blue).

    Gray pin? Or ground pin? Is there a datasheet that shows more details about the led?

    In your diagram, the fourth pin of the top LED is not connected to anything.

    [sel 1] outputs a bang from its left outlet, so it will just bang the numberbox below, causing it to output its current value. Remember that when running pd on Bela the patch will run exactly the same way as if you opened it anew in puredata. That is to say, the number box on the right will probably be a zero and not a one like in the screenshot above. If you want to bang a one, replace it with either a message [1( or a float object initialised to 1 [f 1]

    Sorry I can't find a wiring diagram or spec sheet for the LED from the supplier. And the top LED fourth wire is connected to 3.3v.

    The LED has colored wires of Gray, Red, Green, and Blue. If I send in 3.3v to the gray pin, and connect the red pin to ground, the red LED lights up. Same for green and blue.

    That makes me think I'm using a common Anode LED as in this diagram: [https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black/wiring-common-anode-led
    ](https://)

    Is there any way to control brightness of a common anode RGB LED via Bela and Pure Data? I have the pins plugged into the analog out, but should I instead have analog in? Or can I use PWM with a digital pin?

    Maybe I should just start with a simpler question. In Pure Data, how do I turn on and off the red LED in my diagram? I can work into fading later.

      drumminhands how do I turn on and off the red LED in my diagram?

      Connect it to one of the Bela digital channels, set that channel to be an output at control rate, set it to 1 for off or 0 for on.

      If you are using digital 0 (Pd 11) that's P8.07 and the code would be:

      [loadbang]
      |
      [out 11(
      |
      [s bela_setDigital]
      
      [loadbang]
      |
      [metro 1000]
      |
      [tgl] <<< this is a pd toggle
      |
      [s bela_digitalOut11]

      I think - can't test right now

      For using the analog outs, the usable range depends on the led's characteristics. They'll probably have at least 1.5V forward current Vf. you'll need to output values between 3.3V-Vf and 0V. To convert the 0:1 range in Pd to the 0V:5V analog out range, simply multiply or divide by 5. Long story short, the useful ange from Pd is probably between 0 and 0.36 or less

      10 days later

      So, I have 5 of the RGB arcade buttons that I want to control with Bela. That's 5 digital input pins. Then I need 15 pins to control the RGB LEDs. I can't do them all with digital pins. I have a multiplexer but didn't realize it only expanded the number of analog pins, not digital pins.

      How do i get enough pins to control the LEDs? Can I use other digital pins on the beagblebone or are the ones not shown in the cape wiring diagram off limits?

      Alternatively, if I want to use the analog out pins for the RGB values, you mention the voltage above. But how can Pd control the voltage out. Can you show me a simple Pd diagram that turn on the red LED, but turns off the blue and green LEDs? Essentially something that plugs into [dac~ 3 4 5] to control the voltage?

        Also trying to get one arcade button to work with analog outputs. With a single button press, this does make the LED button red. A second click does turn off all the lights. But more clicks does nothing to the LEDs, only to the print to terminal. What am I getting wrong here turning on and off the LEDs?

        Only use three [sig~] objects for RGB, and set the value of the [sig~] separately.
        The reason why it's not working as expected is that the signal stays at this value and will be mixed at the point where both signals are joined. Stay at the control message domain as long as possible and avoid joining several signals. The [f] objects are not necessary at all in your patch, you can remove them.
        For the print object, use a message feeding to it.

        [off(
        |
        [print LED-status]

        Here's an example of what @max said:
        .

        drumminhands How do i get enough pins to control the LEDs? Can I use other digital pins on the beagblebone or are the ones not shown in the cape wiring diagram off limits?

        You have 16 digital I/O, 8 analog inputs, or up to 64 analog inputs with the multiplexer capelet, and 8 analog outputs. You need to connect 5 buttons and 15 LEDs, so you need 5 inputs and 15 outputs. You can use analog inputs or outputs in lieu of a digital input or output. Some of the combinations that would work in your case are below, whichever you'll pick will depend on what other resources you need:

        • 5 button inputs into the 5 analog inputs, 15 LED outputs from the digitals. This leaves available for further use: up to 3 (or 59) analog inputs, 8 analog outputs, 1 digital output.
        • 5 button inputs into the digital inputs, LED outputs from the analog outputs, 11 LED outputs from the digital outputs, 4. This leaves available for further use: up to 8 (or 64) analog inputs, 4 analog outputs, 1 digital output

        Mix and match the above depending on how many additional analog inputs and/or outputs you need in your project. There is always the possibility to use addressable LEDs (e.g.: WS2812B "neopixel", or SK9822) instead of driving each channel of each LED individually. This approach is slightly more convoluted but frees up most pins (and may require you to purchase different parts). I know you already know about this, but for anyone coming to this post, the resources for this are below