Hi tecsploiters!!
Im going for a short and simple post this time around with a quick look at some cool DUO-LED’s. For those of you that don’t know a Duo LED is a an LED that’s capable of making two colours, in this case the LED can be switched to red or green, or a combination of the two – giving a kind of amber glow.
They are super easy to use, the only difference between them and a normal LED is that they have 3 legs instead of the usual 2!, the LED’s i’m using have a shared negative leg in the middle, and a positive leg each side that controls the intensity of a color (one for green one for red).
You will see in my picture that I havn’t used resistors in series with the LEDs – I should be using 1K resistors here – but i wanted to make the LED as bright as possible, and im not worried about burning them out 😉
In order to demonstrate the colour changing I’ve created a little program for the STM32F4 Discovery that can be used to toggle the colour of the LED between red / green / amber as you can see in this video.
Looks like these would be perfect to make a little traffic light with!
The code can be pasted into the main.c file in my hello world example, and uses the GPIO pins PD3 and PD5
if anyone wants this as a full project let me know!
The code:
/** ****************************************************************************** * @file Duo Red / Green / Amber LED * @author Lee Dyche - Tecsploit.com * @version V1.0.0 * @date 21/03/2014 * @brief External LED that switches between red green and amber. * Based on the hello world example! ****************************************************************************** * @attention * This is program is provided as is with no warranty!! ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f4_discovery.h" /* Private typedef -----------------------------------------------------------*/ GPIO_InitTypeDef GPIO_InitStructure; /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ void Delay(__IO uint32_t nCount); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* GPIOD Periph clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOD, &GPIO_InitStructure); while (1) { GPIO_SetBits(GPIOD, GPIO_Pin_5); Delay(80000000); GPIO_ResetBits(GPIOD, GPIO_Pin_5); GPIO_SetBits(GPIOD, GPIO_Pin_3); Delay(80000000); GPIO_SetBits(GPIOD, GPIO_Pin_5); Delay(80000000); GPIO_ResetBits(GPIOD, GPIO_Pin_3 | GPIO_Pin_5); } } /** * @brief Delay Function. * @param nCount:specifies the Delay time length. * @retval None */ void Delay(__IO uint32_t nCount) { while(nCount--) { } } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */