灯带也会呼吸
在我的开发方案中,有一部分是要用Edison输出PWM 调节LED,使其明暗渐变,模拟阳光。灯带隐藏在枕头内部,发光的枕头以这种温和的方式叫醒用户。本帖22楼已经实现了PWM 输出调节Grove-LED ,为了更好地实现产品化,这里决定用LED灯带。
这两天从网上买的5V灯带到了,买的USB 插口的,改成杜邦线方便连接。
外面是一层滴胶,防水等级IP65。柔性灯带,可做可穿戴开发,内嵌到枕头里面既可以随枕头形状变化,也不会影响舒适感。
之前已经说过关于Edison 上PWM 的输出,这里沿用上次的程序,选择PWM0 输出,对应的引脚是Arduino 拓展板上面的“~3”。正极接“~3”,负极接“GND”。
程序不变,选怎对应的引脚输出PWM即可
// Demo for Grove - Starter V2.0 // Author: Loovee 2013-3-10 // Pulses the Grove - LED with a "breathing" effect. // Connect the Grove - LED to the socket marked D3 // Defines the pin to which the LED is connected. // Any pin that supports PWM can also be used: // 3, 5, 6, 9, 10, 11 const int pinLed = 3; // Define the delay for the "breathing" effect; change this // to a smaller value for a faster effect, larger for slower. const int BREATH_DELAY = 5; // milliseconds void setup() { // Configure the LED's pin for output signals. pinMode(pinLed, OUTPUT); } void loop() { for(int i=0; i<256; i++) { analogWrite(pinLed, i); delay(BREATH_DELAY); } delay(100); for(int i=254; i>=0; i--) { analogWrite(pinLed, i); delay(BREATH_DELAY); } delay(500); }
上传成功,就能看到理想的效果啦~