TCS3472/Esp8266使用记录

文章目录

前言

参考
https://www.bilibili.com/read/cv14207304/
硬件:
esp8266或者nodeMCU
TCS3472模块
ws2812灯带
软件:
arduino IDE
库 : fastled库
TCS库链接
https://pan.baidu.com/s/1yARU2xpdoVXaYBItTL5J2A
提取码:flx5

接线图:(仅适用于本文)

ws2812 ---- esp8266
D0 ----------- GPIO15(或者nodeMCU D 8)
VCC -------- vcc
GND -------- GND

** TCS3472 ---- esp8266 **
SCL---------- GPIO5(或者nodeMCU D1)
SDA---------- GPIO4(或者nodeMCU D2)
VCC -------- vcc
GND -------- GND
在这里插入图片描述

程序

#include <FastLED.h>
#include "MH_TCS34725.h"
#define LED_PIN   15
#define COLOR_ORDER GRB
#define CHIPSET     WS2811
#define NUM_LEDS    20

#define BRIGHTNESS  200
#define FRAMES_PER_SECOND 60

bool gReverseDirection = false;

CRGB leds[NUM_LEDS];
int t =10000;

MH_TCS34725 tcs = MH_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

void setup() {
    Serial.begin(9600);  
  delay(3000); // sanity delay
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness( BRIGHTNESS );
}

void loop()
{

  uint16_t clear, red, green, blue;
  tcs.getRGBC(&red, &green, &blue, &clear);
  tcs.lock();  // turn off LED
  
  // Figure out some basic hex code for visualization
  uint32_t sum = clear;
  float r, g, b;
  r = red; r /= sum;
  g = green; g /= sum;
  b = blue; b /= sum;
  r *= 256; g *= 256; b *= 256;
  // Add entropy to random number generator; we use a lot of it.
  // random16_add_entropy( random());
for(int i=0;i<=NUM_LEDS;i++)
{
  Serial.print(r);  
  
  leds[i]=CRGB((int)r,(int)g,(int)b);
  FastLED.show(); // display this frame
  delay(5);
  }
 //fill_solid(leds, 20, CRGB::Red);
  
  //FastLED.show(); // display this frame
  //FastLED.delay(t / FRAMES_PER_SECOND);
  
 
}



#define COOLING  55

// SPARKING: What chance (out of 255) is there that a new spark will be lit?
// Higher chance = more roaring fire.  Lower chance = more flickery fire.
// Default 120, suggested range 50-200.
#define SPARKING 120


void Fire2012()
{
// Array of temperature readings at each simulation cell
  static byte heat[NUM_LEDS];

  // Step 1.  Cool down every cell a little
    for( int i = 0; i < NUM_LEDS; i++) {
      heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
    }
  
    // Step 2.  Heat from each cell drifts 'up' and diffuses a little
    for( int k= NUM_LEDS - 1; k >= 2; k--) {
      heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
    }
    
    // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
    if( random8() < SPARKING ) {
      int y = random8(7);
      heat[y] = qadd8( heat[y], random8(160,255) );
    }

    // Step 4.  Map from heat cells to LED colors
    for( int j = 0; j < NUM_LEDS; j++) {
      CRGB color = HeatColor( heat[j]);
      int pixelnumber;
      if( gReverseDirection ) {
        pixelnumber = (NUM_LEDS-1) - j;
      } else {
        pixelnumber = j;
      }
      leds[pixelnumber] = color;
    }
}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值