ArduinoRGB 颜⾊渐变代码
这段代码来⾃
在嵌⼊式空间紧张的情况下,如果使⽤HSV颜⾊转换为RGB,会引⼊数学库的⼀些函数,导致固件会明显增⼤。所以直接使⽤RGB控制颜⾊会明显减⼩固件体积。const  int  redPin = 11;const  int  greenPin = 10;const  int  bluePin = 9;void  setup () { // Start off with the LED off. setColourRgb (0,0,0);}void  loop () { unsigned  int  rgbColour [3]; // Start off with red. rgbColour [0] = 255; rgbColour [1] = 0; rgbColour [2] = 0;  // Choose the colours to increment and decrement. for  (int  decColour = 0; decColour < 3; decColour += 1) {  int  incColour = decColour == 2 ? 0 : decColour + 1;  // cross-fade the two colours.  for (int  i = 0; i < 255; i += 1) {    rgbColour [decColour ] -= 1;    rgbColour [incColour ] += 1;    setColourRgb (rgbColour [0], rgbColour [1], rgbColour [2]);    delay (5);  } }}void  setColourRgb (unsigned  int  red , unsigned  int  green , unsigned  int  blue ) { analogWrite (redPin , red ); analogWrite (greenPin , green ); analogWrite (bluePin , blue );}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21渐变颜代码大全
22
23
24
25
26
27
28
29
30

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。