-
Notifications
You must be signed in to change notification settings - Fork 1
/
led.ino
49 lines (43 loc) · 939 Bytes
/
led.ino
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <FastLED.h>
#define LED_PIN 7
#define NUM_LEDS 30
CRGB leds[NUM_LEDS];
String contral="";
int R = 127;
int G = 127;
int B = 127;
void setup() {
Serial.begin(9600); //设置串口波特率9600
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
while(Serial.available()>0){
Serial.println(Serial.read());
R = Serial.read();
G = Serial.read();
B = Serial.read();
for (int i = 0; i <= 29; i++) {
leds[i] = CRGB (R, G, B);
FastLED.show();
delay(300);
}
}
// Red
for (int i = 0; i <= 29; i++) {
leds[i] = CRGB (255, 0, 0);
FastLED.show();
delay(40);
}
// Green
for (int i = 0; i <= 29; i++) {
leds[i] = CRGB (0, 255, 0);
FastLED.show();
delay(40);
}
// Blue
for (int i = 0; i <= 29; i++) {
leds[i] = CRGB (0, 0, 255);
FastLED.show();
delay(40);
}
}