While(true){breathing...}

     Yes, defining a special title for my first post almost cost me half a day -_-. I guess that you have experienced, right?

     So, I would like to start with a special topic "How do you make discretion for the first post when you want to write something?".

     The target for me to create blog aims to share knowledges and experiences with others. At the same time, I also want to gain very important reference and experiences.

     I named "While(true){breathing...}" to the first post. It means ”Adhere to the belief"<坚持的信念> (Translated by google.com). I had created some blogs somewhere already, unfortunatly they are died when each of them borned

 

转载于:https://www.cnblogs.com/EdgarSun/archive/2008/08/16/1269068.html

#include <FastLED.h> #define LED_PIN_1 3 #define LED_PIN_2 6 #define LED_COUNT_1 53 #define LED_COUNT_2 7 #define BRIGHTNESS 255 #define LED_TYPE WS2812B #define COLOR_ORDER GRB CRGB leds_1[LED_COUNT_1]; CRGB leds_2[LED_COUNT_2]; int pin_switch = 10; // 定义数字输入口pin10接收开关状态 int switch_state = 0; // 定义开关状态变量 void setup() { FastLED.addLeds<LED_TYPE, LED_PIN_1, COLOR_ORDER>(leds_1, LED_COUNT_1); FastLED.addLeds<LED_TYPE, LED_PIN_2, COLOR_ORDER>(leds_2, LED_COUNT_2); FastLED.setBrightness(BRIGHTNESS); Serial.begin(9600);//设置串口波特率为9600kbps pinMode(pin_switch, INPUT); // 初始化数字输入口 } void loop() { switch_state = digitalRead(pin_switch); // 读取开关状态 // 开关按下 if (switch_state == LOW) { // 第一条灯带从中间向两边亮起绿色 for (int i = 0; i < LED_COUNT_1 / 2; i++) { leds_1[LED_COUNT_1 / 2 - i - 1].setRGB(0, 255, 0); leds_1[LED_COUNT_1 / 2 + i].setRGB(0, 255, 0); FastLED.show(); delay(50); } //5秒延时 delay(5000); } else { // 开关未按下,灯带状态为白色呼吸灯 bool breathing = true; // 定义一个变量用于记录呼吸灯状态 while (breathing) { // 当呼吸灯状态为true时,执行循环 int brightness = 0; for (int i = 0; i < 7680; i++) { brightness = (exp(sin(i / 50.0 * PI)) - 0.36787944) * 108.0; for (int j = 0; j < LED_COUNT_1; j++) { leds_1[j].setRGB(brightness, brightness, brightness); } FastLED.show(); delay(10); switch_state = digitalRead(pin_switch); if (switch_state == LOW) { // 如果开关被按下,退出循环 breathing = false; break; } } } } }在5秒延时之后添加慢慢熄灭灯带
最新发布
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值