ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
WS2812_ATY.c
Go to the documentation of this file.
1
27#ifndef __WS2812_ATY_C
28#define __WS2812_ATY_C
29
30#include "WS2812_ATY.h"
31
32/******************************* For user *************************************/
33
34/******************************************************************************/
35
36#ifdef __STC51_ATY
44void WS2812_SetBit(uint8_t dataBit)
45{
46 if(dataBit)
47 {
48 // 24MHz-1T
49 GPIO_SET_H(WS2812_PIN);
50 _nop_();
51 _nop_();
52 _nop_();
53 _nop_();
54 _nop_();
55 _nop_();
56 _nop_();
57 _nop_();
58 _nop_();
59 GPIO_SET_L(WS2812_PIN);
60 _nop_();
61 _nop_();
62 _nop_();
63 }
64 else
65 {
66 GPIO_SET_H(WS2812_PIN);
67 _nop_();
68 _nop_();
69 _nop_();
70 GPIO_SET_L(WS2812_PIN);
71 _nop_();
72 _nop_();
73 _nop_();
74 _nop_();
75 _nop_();
76 _nop_();
77 _nop_();
78 }
79}
80#endif /* __STC51_ATY */
81
82#ifdef __ESP8266_ATY
83#include "HW_SPI_ATY.h"
91void WS2812_SetBit(uint8_t dataBit)
92{
93 if(dataBit)
94 SPI_Write(0xFC, 1);
95 else
96 SPI_Write(0x3F, 1);
97}
98#endif /* __ESP8266_ATY */
99
100
108{
109 WS2812_SetBit(G & 0X80);
110 WS2812_SetBit(G & 0X40);
111 WS2812_SetBit(G & 0X20);
112 WS2812_SetBit(G & 0X10);
113 WS2812_SetBit(G & 0X08);
114 WS2812_SetBit(G & 0X04);
115 WS2812_SetBit(G & 0X02);
116 WS2812_SetBit(G & 0X01);
117 WS2812_SetBit(R & 0X80);
118 WS2812_SetBit(R & 0X40);
119 WS2812_SetBit(R & 0X20);
120 WS2812_SetBit(R & 0X10);
121 WS2812_SetBit(R & 0X08);
122 WS2812_SetBit(R & 0X04);
123 WS2812_SetBit(R & 0X02);
124 WS2812_SetBit(R & 0X01);
125 WS2812_SetBit(B & 0X80);
126 WS2812_SetBit(B & 0X40);
127 WS2812_SetBit(B & 0X20);
128 WS2812_SetBit(B & 0X10);
129 WS2812_SetBit(B & 0X08);
130 WS2812_SetBit(B & 0X04);
131 WS2812_SetBit(B & 0X02);
132 WS2812_SetBit(B & 0X01);
133}
134
135#ifdef __DEBUG_WS2812_ATY
139void WS2812_Test(void)
140{
141#define MAX_TIME_WS2812_TEST 10000
142 uint16_t i = 0;
143 WS2812_SetColor(255, 0, 0);
144 for(i = 0; i < 10000; i++){}
145 WS2812_SetColor(255, 255, 0);
146 for(i = 0; i < 10000; i++){}
147 WS2812_SetColor(0, 255, 0);
148 for(i = 0; i < 10000; i++){}
149 WS2812_SetColor(0, 255, 255);
150 for(i = 0; i < 10000; i++){}
151 WS2812_SetColor(0, 0, 255);
152 for(i = 0; i < 10000; i++){}
153 WS2812_SetColor(255, 0, 255);
154 for(i = 0; i < 10000; i++){}
155}
156
160void WS2812_StyleA(void)
161{
162 // (255, 0 ,0)
163 // (255, 255 ,0)
164 // (0, 255 ,0)
165 // (0, 255 ,255)
166 // (0, 0 ,255)
167 // (255, 0 ,255)
168 // (255, 0 ,0)
169 uint16_t i = 0, j = 0;
170 uint16_t r = 255, g = 0, b = 0;
171 uint8_t staRGB = 0;
172 while(1)
173 {
174 // for(i = 0; i < 80; i++)
175 {
176 // for(j = 0; j < 7; j++)
177 WS2812_SetColor(r, g, b);
178 {
179 uint8_t i_t = 0;
180 for(i = 0; i < 100; i++){}
181 }
182 }
183
184 switch(staRGB)
185 {
186 case 0: g++; break;
187 case 1: r--; break;
188 case 2: b++; break;
189 case 3: g--; break;
190 case 4: r++; break;
191 case 5: b--; break;
192 }
193
194 if(r >= 255 && g <= 0 && b <= 0)
195 staRGB = 0;
196 else if(r >= 255 && g >= 255 && b <= 0)
197 staRGB = 1;
198 else if(r <= 0 && g >= 255 && b <= 0)
199 staRGB = 2;
200 else if(r <= 0 && g >= 255 && b >= 255)
201 staRGB = 3;
202 else if(r <= 0 && g <= 0 && b >= 255)
203 staRGB = 4;
204 else if(r >= 255 && g <= 0 && b >= 255)
205 staRGB = 5;
206 }
207}
208
209
210//void main()
211//{
212// while (1)
213// {
214// // WS2812_test();
215// WS2812_styleA();
216// }
217//}
218#endif /* __DEBUG_WS2812_ATY */
219
220
221#endif /* __WS2812_ATY_C */
222
223/******************************** End Of File *********************************/
Familiar functions of SPI for all embedded device.
uint8_t SPI_Write(uint8_t *data_t, uint16_t len)
void WS2812_SetColor(uint8_t R, uint8_t G, uint8_t B)
Set colors.
Definition: WS2812_ATY.c:107
Base functions of WS2812 for all embedded device.
void WS2812_SetBit(uint8_t dataBit)
unsigned short uint16_t
Definition: fw_types.h:19
unsigned char uint8_t
Definition: fw_types.h:18
uint8_t __XDATA i