java - Arduino 自动调光器
问题描述
我正在尝试通过仅输入秒数来使 Adafruit 的 NEOPIXEL 变暗,但我无法实现平滑过渡,并且最多只能使用 5 秒。而且我无法让它打印当前的亮度。:(
这是我的代码:
#include <Adafruit_NeoPixel.h>
#define PIN 4
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(3, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
double t = 2000;
dimmerByTime(t);
}
void dimmerByTime(int time){
int seq = time / 170;
int b = 100 /seq;
for (int i = 1; i < seq; i++) {
strip.setPixelColor(0, 0, 100, 200);
strip.setPixelColor(1, 0, 100, 10);
strip.setPixelColor(2, 0, 0, 225);
strip.setBrightness(b);
strip.show();
delay(170);
b = b + b;
Serial.println(i);
Serial.println("Brightness @");
Serial.println(b);
}
}
谢谢!
解决方案
要启用打印,请在 void setup() 添加: Serial.begin(9600);
双 t = 2000; 可以是int t = 2000;
在函数 dimmerByTime 中,for 循环仅循环 10 次(seq = 2000/170 = 11)。int b 每次翻倍(第一次:b=9,第二次:b=18 等)。尝试一个固定的数字,看看发生了什么(例如 b += 10)。或者尝试更小的步骤并消除(或减少)延迟,与 for 循环结合使用(迭代超过 10 次)。
调光通常使用不同的变量设置。
推荐阅读
- sql - Oracle CASE 下一个工作日
- linux-kernel - Yocto Krogoth 的 IP 表
- javascript - 加载 video.js 时出现奇怪的帧
- elasticsearch - 将 Elasticsearch 慢日志设置恢复为默认值
- angular - 无法在 amchart 中设置时间 HH:mm:ss?
- c++ - 用于强类型枚举的模板化运算符
- node.js - 从 Angular 前端到 json-server 的 GET 调用访问被 CORS 策略阻止的 XMLHttpRequest
- c# - 如何从 .net 核心应用程序中触发 IotEdge 模块上的计算?
- sql - 将变量和表参数之间的结果插入表中
- databricks - 如何以特定顺序使用 Databricks dbutilis 复制文件