R、G或B三種顏色的LED晶片在相同電流驅動下,會有不一樣的亮度結果,因此使用GY-30(BH1750FVI)進行光強度測量。

 

1.硬體操作

控制板:Arduino UNO

材料: WS2812 LED、GY-30光強度感測器

 

2.程式

#include 

/*
  Arduino UNO
  VCC  <-> 3V3 grijs
  GND  <-> Gnd paars
  SDA  <-> A4  groen
  SCL  <-> A5  blauw
  ADDR <-> D13  geel
 */
#include <BH1750FVI.h>
#include <Wire.h>
#include <WS2812.h>

#define outputPin 7  // Digital output pin (default: 7)
#define LEDCount 2   // Number of LEDs to drive (default: 9)
WS2812 LED(LEDCount); 
cRGB value;
int i = 0;
int j = 0 ;
// Settings
uint8_t ADDRESSPIN = 13;
BH1750FVI::eDeviceAddress_t DEVICEADDRESS = BH1750FVI::k_DevAddress_H;
BH1750FVI::eDeviceMode_t DEVICEMODE = BH1750FVI::k_DevModeContHighRes;

// Create the Lightsensor instance
BH1750FVI LightSensor(ADDRESSPIN, DEVICEADDRESS, DEVICEMODE);

void setup() 
{
  LED.setOutput(outputPin); // Digital Pin 7
  Serial.begin(115200);
  LightSensor.begin();  
  Serial.println("Running...");
}

void loop()
{
  //每個顏色執行前先調暗
  while(j<=2){
  value.b = 0; 
  value.g = 0; 
  value.r = 0; 
  LED.set_crgb_at(0, value); 
  value.b = 0; 
  value.g = 0; 
  value.r = 0; 
  LED.set_crgb_at(1, value); 
  LED.sync(); // Sends the data to the LEDs
  
  delay(1000);
  
    while (i <= (255)){
     //因是測量第二顆,因此第一顆調暗.
      value.b = 0; 
      value.g = 0; 
      value.r = 0; 
      LED.set_crgb_at(0, value); 
      
      //依序測量RGB三個顏色的0-255階調變化
      value.g = i*((j%3)%2); 
      value.r = i*(((j+1)%3)%2);
      value.b = i*(((j+2)%3)%2);
      LED.set_crgb_at(1, value);
      LED.sync(); // Sends the data to the LEDs
      delay(100);
      uint16_t lux = LightSensor.GetLightIntensity();
      Serial.print(j);
      Serial.print("L");
      Serial.print(i);
      Serial.print(":");
      Serial.println(lux);
      delay(100);
      i++;
    }
    i=0;
    j++;
  }
}

監控視窗讀取數值

將量測資料帶入Excel進行比較,發現綠色亮度最高,藍色最弱,且幾乎是綠色的一半。

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 門外漢 的頭像
    門外漢

    門外漢的筆記

    門外漢 發表在 痞客邦 留言(0) 人氣()