#include <FastLED.h>
// How many leds in your strip?
#define NUM_LEDS 16
#define DATA_PIN 2
CRGB leds[NUM_LEDS];
void setup() {
// 设置 13 号 引脚 输出模式: OUTPUT 输入模式: INPUT
Serial.begin(115200);
Serial.println("resetting");
FastLED.addLeds<WS2812,DATA_PIN,GRB>(leds,NUM_LEDS);
FastLED.setBrightness(84);
}
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
void loop() {
static uint8_t hue = 0;
Serial.print("x");
// First slide the led in one direction
for(int i = 0; i < NUM_LEDS; i++) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
Serial.print("x");
// Now go in the other direction.
for(int i = (NUM_LEDS)-1; i >= 0; i--) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
}
// 必须
// 按钮按下,led 亮
// 按钮松开,led 灭
// 拓展
// 默认初始状态 led 灭的
// 第1次按,led 长亮
// 第2次按,led 长灭
// 第3次按,led 长亮
// C/C++
// int a = 1;
// int a;
// a = 1;
// int integer 整数类型 1/2/3/10 。。。。
// float 浮点数 1.0/2.3/3.14 。。。
// bool 布尔类型 true/false if()
// String 字符串 "1"/"1.0"/"true"/"你好" 。。。。
// a 变量名
// = 赋值符号
// a = a + 1;
// // 简写
// a += 1; // a -= 1; a *= 1; a /= 1;
// a++; // a--;
// a = 2;
// if(a > 10)
// {
// // 满足条件 执行的代码
// }
// else
// {
// // 不满足条件 执行的代码
// }
// 注释
// 函数/方法