Skip to main content
cl.1_99
Associate II
March 21, 2020
Question

Is it possible to mix different amounts of colours in an RGB LED using HAL_GPIO_WritePin pinSet, as in WITHOUT using PWM?

I have a thermistor hooked up to the nucleo-l432kc to obtain temperature and display that temp on an LCD, print it to the screen, and light up a specific colour of an RGB LED. I want to be able to combine two colours of an RGB LED in different amounts, so not just have them both ON at full, but instead have one a bit less than the other (to make orange). I tried this using PWM and it worked, but for some reason it causes other parts of my circuit/program to malfunction (it ends up displaying an incorrect temp only when I use PWM and I do not know why). Any suggestions how to do this only using gpio outputs?

This topic has been closed for replies.

2 replies

TDK
March 22, 2020

There are a few ways.

1) Set up an interrupt to happen at 1kHz. Within that interrupt, set RGB pin values based on the color mix you want.

2) Set up a circular memory to GPIO->BSRR peripheral DMA transfer to happen at 1kHz (or whatever) and define values to get the mix you want.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Piranha
Principal III
March 23, 2020

To create analog adjusting levels with a digital output, you need some modulation, typically PWM. If you create PWM signal not using timer peripheral, that is still the same PWM signal, only with less effective use of MCU resources.

Understand and solve the real problem, not search for some magic "solutions"!