Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8105af6

Browse files
committed
library: add RGB LED TLC59731
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parentbb11ba8 commit8105af6

File tree

5 files changed

+311
-0
lines changed

5 files changed

+311
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
RGB_LED_TLC59731
3+
4+
This example code is in the public domain.
5+
6+
Blink one RGB LED with different default colors:
7+
RGB_LED_TLC59731::OFF
8+
RGB_LED_TLC59731::RED
9+
RGB_LED_TLC59731::GREEN
10+
RGB_LED_TLC59731::BLUE
11+
RGB_LED_TLC59731::MAGENTA
12+
RGB_LED_TLC59731::CYAN
13+
RGB_LED_TLC59731::YELLOW
14+
RGB_LED_TLC59731::WHITE
15+
*/
16+
17+
#include<RGB_LED_TLC59731.h>
18+
19+
staticuint8_t step =1;
20+
21+
/**
22+
STM32WB5MM-DK have an RGB LED connected to TLC59731
23+
It requires to enable it thanks LED_SELECT pin
24+
and to have JP5 on and JP4 off
25+
*/
26+
#if defined(RGB_LED) && defined(LED_SELECT)
27+
RGB_LED_TLC59731LED(RGB_LED, LED_SELECT);
28+
#else
29+
RGB_LED_TLC59731LED();
30+
#endif
31+
32+
voidsetup() {
33+
/* Change default brightness*/
34+
LED.setBrightness(0x10);
35+
}
36+
37+
voidloop() {
38+
uint8_t *color = RGB_LED_TLC59731::OFF;
39+
switch (step) {
40+
case1:
41+
color = RGB_LED_TLC59731::RED;
42+
break;
43+
case2:
44+
color = RGB_LED_TLC59731::GREEN;
45+
break;
46+
case4:
47+
color = RGB_LED_TLC59731::BLUE;
48+
break;
49+
case8:
50+
color = RGB_LED_TLC59731::MAGENTA;
51+
break;
52+
case16:
53+
color = RGB_LED_TLC59731::CYAN;
54+
break;
55+
case32:
56+
color = RGB_LED_TLC59731::YELLOW;
57+
break;
58+
case64:
59+
color = RGB_LED_TLC59731::WHITE;
60+
break;
61+
default:
62+
color = RGB_LED_TLC59731::OFF;
63+
break;
64+
}
65+
/* Blink*/
66+
LED.on(color);
67+
delay(500);
68+
LED.off();
69+
delay(500);
70+
step = (step ==64) ?1 : step *2;
71+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#######################################
2+
# Syntax Coloring Map For RGB_LED_TLC59731
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
RGB_LED_TLC59731KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
onKEYWORD2
16+
offKEYWORD2
17+
getBrightnessKEYWORD2
18+
setBrightnessKEYWORD2
19+
20+
#######################################
21+
# Constants (LITERAL1)
22+
#######################################
23+
24+
OFFLITERAL1
25+
REDLITERAL1
26+
GREENLITERAL1
27+
BLUELITERAL1
28+
MAGENTALITERAL1
29+
CYANLITERAL1
30+
YELLOWLITERAL1
31+
WHITELITERAL
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=RGB LED TLC59731
2+
version=1.0.0
3+
author=Frederic Pillon
4+
maintainer=stm32duino
5+
sentence=Allows to control one RGB LED driven by TLC59731 PWM LED Driver
6+
paragraph=Control one RGB LED driven by TLC59731 PWM LED Driver
7+
category=Signal Input/Output
8+
url=https://github.com/stm32duino/Arduino_Core_STM32/tree/master/libraries/RGB_LED_TLC59731
9+
architectures=stm32
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
13+
#include"RGB_LED_TLC59731.h"
14+
15+
#defineWRITE_COMMAND0x3A
16+
#ifndef DEFAULT_BRIGHTNESS
17+
#defineDEFAULT_BRIGHTNESS0x41
18+
#endif
19+
uint8_t RGB_LED_TLC59731::brightness = DEFAULT_BRIGHTNESS;
20+
uint8_t RGB_LED_TLC59731::OFF[3] = {0,0,0 };
21+
uint8_t RGB_LED_TLC59731::RED[3] = {DEFAULT_BRIGHTNESS,0,0 };
22+
uint8_t RGB_LED_TLC59731::GREEN[3] = {0, DEFAULT_BRIGHTNESS,0 };
23+
uint8_t RGB_LED_TLC59731::BLUE[3] = {0,0, DEFAULT_BRIGHTNESS};
24+
uint8_t RGB_LED_TLC59731::MAGENTA[3] = {DEFAULT_BRIGHTNESS,0, DEFAULT_BRIGHTNESS};
25+
uint8_t RGB_LED_TLC59731::CYAN[3] = {0, DEFAULT_BRIGHTNESS, DEFAULT_BRIGHTNESS};
26+
uint8_t RGB_LED_TLC59731::YELLOW[3] = {DEFAULT_BRIGHTNESS, DEFAULT_BRIGHTNESS,0 };
27+
uint8_t RGB_LED_TLC59731::WHITE[3] = {DEFAULT_BRIGHTNESS, DEFAULT_BRIGHTNESS, DEFAULT_BRIGHTNESS};
28+
29+
/**
30+
* @brief Set RGB LED color
31+
* @param rgb[3]: red,green, blue value in range [0-255]
32+
* @retval None
33+
*/
34+
voidRGB_LED_TLC59731::on(uint8_t rgb[3])
35+
{
36+
on(rgb[0], rgb[1], rgb[2]);
37+
}
38+
39+
/**
40+
* @brief Set RGB LED color
41+
* @param red: red value in range [0-255]
42+
* @param green: green value in range [0-255]
43+
* @param blue: blue value in range [0-255]
44+
* @retval None
45+
*/
46+
voidRGB_LED_TLC59731::on(uint8_t red,uint8_t green,uint8_t blue)
47+
{
48+
if (!_enabled) {
49+
if (_enable_pin != NC) {
50+
pinMode(pinNametoDigitalPin(_enable_pin), OUTPUT);
51+
digitalWriteFast(_enable_pin, HIGH);
52+
}
53+
54+
pinMode(pinNametoDigitalPin(_rgb_pin), OUTPUT);
55+
_enabled =true;
56+
}
57+
/* Data Transfer Rate (T_CYCLE) Measurement Sequence*/
58+
digitalWriteFast(_rgb_pin, HIGH);
59+
delayMicroseconds(_T_Rise);
60+
digitalWriteFast(_rgb_pin, LOW);
61+
delayMicroseconds(_T_Cycle0);
62+
/* Write command*/
63+
senByte(WRITE_COMMAND);
64+
/* Write the GS data*/
65+
senByte(red);
66+
senByte(green);
67+
senByte(blue);
68+
/* GS Latch*/
69+
delayMicroseconds(_T_GS_Lat);
70+
}
71+
72+
/**
73+
* @brief Set RGB LED Off
74+
* @param None
75+
* @retval None
76+
*/
77+
voidRGB_LED_TLC59731::off(void)
78+
{
79+
/* Set RGB LED off value*/
80+
on(RGB_LED_TLC59731::OFF);
81+
pinMode(pinNametoDigitalPin(_rgb_pin), INPUT_ANALOG);
82+
83+
if (_enable_pin != NC) {
84+
digitalWriteFast(_enable_pin, LOW);
85+
pinMode(pinNametoDigitalPin(_enable_pin), INPUT_ANALOG);
86+
_enabled =false;
87+
}
88+
}
89+
90+
/**
91+
* @brief Set brightness value
92+
* @param value: new brightness value
93+
* @retval None
94+
*/
95+
voidRGB_LED_TLC59731::setBrightness(uint8_t value)
96+
{
97+
RGB_LED_TLC59731::brightness = value;
98+
RGB_LED_TLC59731::RED[0] = value;
99+
RGB_LED_TLC59731::GREEN[1] = value;
100+
RGB_LED_TLC59731::BLUE[2] = value;
101+
RGB_LED_TLC59731::MAGENTA[0] = value;
102+
RGB_LED_TLC59731::MAGENTA[2] = value;
103+
RGB_LED_TLC59731::CYAN[1] = value;
104+
RGB_LED_TLC59731::CYAN[2] = value;
105+
RGB_LED_TLC59731::YELLOW[0] = value;
106+
RGB_LED_TLC59731::YELLOW[1] = value;
107+
RGB_LED_TLC59731::WHITE[0] = value;
108+
RGB_LED_TLC59731::WHITE[1] = value;
109+
RGB_LED_TLC59731::WHITE[2] = value;
110+
}
111+
112+
/* Private*/
113+
voidRGB_LED_TLC59731::sendBit(uint8_t bit)
114+
{
115+
/* Start next cycle*/
116+
digitalWriteFast(_rgb_pin, HIGH);
117+
delayMicroseconds(_T_Rise);
118+
digitalWriteFast(_rgb_pin, LOW);
119+
delayMicroseconds(_T_Rise);
120+
121+
if (bit) {
122+
digitalWriteFast(_rgb_pin, HIGH);
123+
delayMicroseconds(_T_Rise);
124+
digitalWriteFast(_rgb_pin, LOW);
125+
delayMicroseconds(_T_Cycle1);
126+
}else {
127+
delayMicroseconds(_T_Cycle0);
128+
}
129+
}
130+
131+
132+
voidRGB_LED_TLC59731::senByte(uint8_t byte)
133+
{
134+
sendBit(byte & (1 <<7));
135+
sendBit(byte & (1 <<6));
136+
sendBit(byte & (1 <<5));
137+
sendBit(byte & (1 <<4));
138+
sendBit(byte & (1 <<3));
139+
sendBit(byte & (1 <<2));
140+
sendBit(byte & (1 <<1));
141+
sendBit(byte & (1 <<0));
142+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
13+
#ifndef __RGB_LED_TLC59731_H__
14+
#define__RGB_LED_TLC59731_H__
15+
16+
#include"Arduino.h"
17+
18+
classRGB_LED_TLC59731 {
19+
20+
public:
21+
RGB_LED_TLC59731(uint32_t rgb_pin = LED_BUILTIN,uint32_t enable_pin = NC):
22+
_rgb_pin(digitalPinToPinName(rgb_pin)), _enable_pin(digitalPinToPinName(enable_pin)) {};
23+
voidon(uint8_t rgb[3]);
24+
voidon(uint8_t red,uint8_t green,uint8_t blue);
25+
voidoff(void);
26+
inlineuint8_tgetBrightness(void)
27+
{
28+
return brightness;
29+
}
30+
voidsetBrightness(uint8_t value);
31+
32+
staticuint8_t brightness;
33+
staticuint8_t OFF[3];
34+
staticuint8_t RED[3];
35+
staticuint8_t GREEN[3];
36+
staticuint8_t BLUE[3];
37+
staticuint8_t MAGENTA[3];
38+
staticuint8_t CYAN[3];
39+
staticuint8_t YELLOW[3];
40+
staticuint8_t WHITE[3];
41+
42+
private:
43+
PinName _rgb_pin;
44+
PinName _enable_pin;
45+
46+
bool _enabled{false};
47+
constuint32_t _T_Rise{1};
48+
constuint32_t _T_Cycle0{4};
49+
constuint32_t _T_Cycle1{1};
50+
// GS Data Latch (GSLAT) Sequence delay
51+
constuint32_t _T_GS_Lat{_T_Cycle0 *8};
52+
53+
voidsendBit(uint8_t bit);
54+
voidsenByte(uint8_t byte);
55+
};
56+
57+
// extern IWatchdogClass IWatchdog;
58+
#endif/* __RGB_LED_TLC59731_H__*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp