---
# System prepended metadata

title: arduino temp

---

# arduino temp
#include "FastLED.h"
#define NUM_LEDS 144             // LED灯珠数量
#define LED_DT 2                // Arduino输出控制信号引脚
#define LED_TYPE WS2812         // LED灯带型号
#define COLOR_ORDER GRB  
uint8_t max_bright = 255;       // LED亮度控制变量，可使用数值为 0 ～ 255， 数值越大则光带亮度越高
CRGB leds[NUM_LEDS];     // 建立光带leds
CHSV myHSVcolor(80,255,200);  
int h,s,v,cnt=0;
int hTemp[10],sTemp[10],vTemp[10];
void setup() {
  // put your setup code here, to run once:
    pinMode(3,INPUT_PULLUP);
    pinMode(4,INPUT_PULLUP);
    LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);  // 初始化光带
    FastLED.setBrightness(max_bright);
    Serial.begin(9600);  
}

void loop() {
  // put your main code here, to run repeatedly:
    if(digitalRead(3) == 0)
    {
      h++;
      delay(analogRead(0));
      if(h > 255)
        h = 0;
      myHSVcolor.h = h;
      myHSVcolor.s = 255;
      myHSVcolor.v = map(analogRead(2),0,1023,0,255);  
      fill_solid(leds, NUM_LEDS, myHSVcolor);
    }
    else if(digitalRead(4) == 0)
    {   
      fill_rainbow(leds, NUM_LEDS, h++, 1);
      if(h > 255)
        h = 0; 
    }
    else
    {
      hTemp[cnt] = map(analogRead(0),0,1023,0,255);
      sTemp[cnt] = map(analogRead(1),0,1023,155,255);
      vTemp[cnt] = map(analogRead(2),0,1023,0,255);
      cnt++;
      if(cnt > 9)
        cnt = 0;
      h=0;
      s=0;
      v=0;  
      for(int i=0;i<10;i++)
      {
        h = h + hTemp[i];
        s = s + sTemp[i];
        v = v + vTemp[i];
      }
      h = h / 10;
      s = s / 10;
      v = v / 10;
      if(h < 0)
        h = 0;
      if(h > 255)
        h = 255;  
      if(s < 155)
        s = 155;
      if(s > 255)
        s = 255;
      if(v < 0)
        v = 0;
      if(v > 255)
        v = 255;   
      myHSVcolor.h = h;
      myHSVcolor.s = s;
      myHSVcolor.v = v;  
      fill_solid(leds, NUM_LEDS, myHSVcolor);    
    }       

    Serial.print(h);
    Serial.print(",");
    Serial.print(s);
    Serial.print(",");
    Serial.println(v);
    
    FastLED.show(); 
    delay(10);
}