海玻璃呼吸灯

创意展示、DIY分享、经验交流
回复

头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

Re: 海玻璃呼吸灯

#2

帖子 shaoziyang »

参考代码

代码: 全选

// sea_glass
//
// Copyright (c) 2018 John Graham-Cumming
//
// Makes four LEDs from an AdaFruit NeoPixel strip "breath" in white
// as part of a small lamp made from a glass and white, green and brown
// pieces of sea glass found on a beach.

#include <Adafruit_NeoPixel.h>

#define PIN 0
Adafruit_NeoPixel strip = Adafruit_NeoPixel(4, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show();
}

// Formula for breathing from...
//     https://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/

void loop() {
  float val = (exp(sin(millis()*0.5/2000.0*PI)) - 0.36787944)*108.0;
  
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, strip.Color(val, val, val));
  }
  
  strip.show();
}
 

头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

Re: 海玻璃呼吸灯

#3

帖子 shaoziyang »

LED 亮度的公式为

图片

其中 x 是自开始以来的毫秒数。绘制曲线看起来像这样

图片

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章