基于BH1750FVI光照传感模块的入射…

平台:Arduino

IDE:Arduino 1.6.7

 

BH1750FVI模块,基于IIC总线

 

程序模块流程描述:

1.驱动BH1750FVI,将获得的数据转化为整数型并存储(单位LX)

2.通过算法将LX转为EV值

3.构建光圈表和快门速度表,对照EV表进行查询

4.得到最合适的快门速度,依据ISO进行偏移,得到在对应光圈,ISO和光强下最终的快门速度(结果)

 

 

//主函数文件,包括了对BH1750的声明,测试平台为Arduino UNO,IIC接口为A4,A5.

//Base on BH1750 sensor modle


#include //IIC
#include
int BH1750address = 0x23;
byte buff[2];
void setup()
{
  Wire.begin();
  Serial.begin(9600);
}
void loop()//MyBlgo:http://blog.sina.com.cn/u/3909624897, if you have some question

{
  int i;
  uint16_t val = 0;
  BH1750_Init(BH1750address);
  delay(1000);
  if (2 == BH1750_Read(BH1750address))
  {
    val = ((buff[0] << 8) | buff[1]) / 1.2;
     //Serial.println("==================================");
    LuxToEV(val);
       
  EVandIrisToCountOutSpeed();
   SerialPrint();
   Serial.println(" ");
    Serial.print(val, DEC);
    Serial.println(" lux");
    Serial.print("==================================");


   // LuxToShutterSpeed(val);
  }
  delay(150);
}


int BH1750_Read(int address) //
{

  int i = 0;
  Wire.beginTransmission(address);
  Wire.requestFrom(address, 2);
  while (Wire.available()) //
  {
    buff[i] = Wire.read();  // receive one byte
    i++;
  }
  Wire.endTransmission();
  return i;
}

void BH1750_Init(int address)
{
  Wire.beginTransmission(address);
  Wire.write(0x10);//1lx reolution 120ms
  Wire.endTransmission();

}

 

 

 

//测光表函数文件,包含有转换EV数值,进行快门-光圈-EV表格筛选等函数

int H, E, T; //H = E x T;E = I x T;
const int ISO[10] ={100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600};
int Iris , SpeedM = 0, R = 2 , M=0, I=1;//R is iris area number,M is speed area number,I is is number ,default is ISO 100
int Elux;//AS the balance reference of expose and lux;
float EV;
int i,j;//MyBlgo:http://blog.sina.com.cn/u/3909624897, if you have some question
int EVSeries[14][11] = {//The matrix of EV,x is iris num,y is shutter speed num
                    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
                    2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
                    3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
                    4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                    5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
                    6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
                    7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
                    8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
                    9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
                    10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
                    11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
                   
                    };
                   
float IrisR[11] = {1.0, 1.4, 2.0, 2.8, 4.0, 5.6, 8.0, 11.0, 16.0, 22.0, 32.0};
int Speed[14] = { 8000, 4000, 2000, 1000, 500, 250, 125, 60, 30, 15, 8, 4, 2 , 1 };
int CankaoLUX[18] = {2.5, 5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240, 20480, 40960, 81920, 163840};
 void LuxToEV(int lux)
{
  for (i = 0; i < 18; i++)
  {
    if (lux > CankaoLUX[i] && lux < CankaoLUX[i + 1])
    {
      EV = float((lux-CankaoLUX[i])/ (CankaoLUX[i+1]-CankaoLUX[i])) +i;
     
      Serial.print(EV);
      Serial.println("EV");
      break;
    }
  }
}
void EVandIrisToCountOutSpeed()
{
 
  for(i=1;i<14;i++)
    {
      if (EV== EVSeries[i][R-1])
      {
        //Serial.println(EVSeries[i][R]);
        M = i-1;//Make M(the speed vs number) equal to count number;
        break;
      }
    }
     
}


void SerialPrint()
{
 
  Serial.print(" Iris:");
  Serial.print(IrisR[R]);
  Serial.print(" Speed:1/");
  Serial.print(Speed[13-M-I]);//The speed is 13-M and I(ISO number)
   Serial.println("s ");
  Serial.print(" ISO:");
  Serial.print(ISO[I]);
 
 // Serial.print(SpeedM);
}

 

基于BH1750FVI光照传感模块的入射式摄影测光表

 

 

 

参考资料:
基于BH1750FVI光照传感模块的入射式摄影测光表


基于BH1750FVI光照传感模块的入射式摄影测光表

 

 


基于BH1750FVI光照传感模块的入射式摄影测光表


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值