lot of cleanups

This commit is contained in:
Johannes Findeisen 2015-08-26 01:39:01 +02:00
commit a3571ceb42
3 changed files with 22 additions and 57 deletions

View file

@ -1,68 +1,21 @@
/*
This is a simple code to test BH1750FVI Light senosr
communicate using I2C Protocol
this library enable 2 slave device address
Main address 0x23
secondary address 0x5C
connect this sensor as following :
VCC >>> 3.3V
SDA >>> A4
SCL >>> A5
addr >> A3
Gnd >>>Gnd
Written By : Mohannad Rawashdeh
*/
// First define the library :
// Written 2015 by Johannes Findeisen <you@hanez.org>
#include <Wire.h>
#include <BH1750FVI.h>
BH1750FVI LightSensor;
void setup() { // put your setup code here, to run once:
Serial.begin(9600);
void setup() {
Serial.begin(9600);
LightSensor.begin();
/*
Set the address for this sensor
you can use 2 different address
Device_Address_H "0x5C"
Device_Address_L "0x23"
you must connect Addr pin to A3 .
*/
LightSensor.SetAddress(Device_Address_L);//Address 0x5C
// To adjust the slave on other address , uncomment this line
// lightMeter.SetAddress(Device_Address_L); //Address 0x5C
//-----------------------------------------------
/*
set the Working Mode for this sensor
Select the following Mode:
Continuous_H_resolution_Mode
Continuous_H_resolution_Mode2
Continuous_L_resolution_Mode
OneTime_H_resolution_Mode
OneTime_H_resolution_Mode2
OneTime_L_resolution_Mode
The data sheet recommanded To use Continuous_H_resolution_Mode
*/
LightSensor.SetAddress(Device_Address_L);
LightSensor.SetMode(Continuous_H_resolution_Mode);
Serial.println("Running...");
}
void loop() {
// put your main code here, to run repeatedly:
uint16_t lux = LightSensor.GetLightIntensity();// Get Lux value
Serial.print("LightX: ");
uint16_t lux = LightSensor.GetLightIntensity(); // Get Lux value
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lux");
delay(250);
delay(1000);
}

View file

@ -1,3 +1,4 @@
// Written 2015 by Johannes Findeisen <you@hanez.org>
#include <Wire.h>

View file

@ -35,23 +35,29 @@ void setup()
pinMode(ledPin, OUTPUT);
Wire.begin();
LightSensor.begin();
LightSensor.SetAddress(Device_Address_L); // Address 0x23
LightSensor.SetMode(Continuous_H_resolution_Mode);
lcd.init();
lcd.backlight();
// Get data for the first time.
// Read this to understand the temperature calculation:
// http://www.danielandrade.net/2008/07/05/temperature-sensor-arduino/
tempC = (5.0 * analogRead(tempPin) * 100.0) / 1024.0;
tempClast = tempC;
// Celsius to Fahrenheit conversion
tempF = (tempC * 9) / 5 + 32;
// Get light sensor data
lux = LightSensor.GetLightIntensity();
// Get data from other Arduino on 0x07
read_wire();
// Refresh the LCD output
lcd_refresh();
}
@ -69,14 +75,19 @@ void loop()
}
// Calculate temperature
tempC = tempC / (float)samples;
// Celsius to Fahrenheit conversion.
tempF = (tempC * 9) / 5 + 32;
// Get light sensor data
lux = LightSensor.GetLightIntensity();
// Get data from I2C attached Arduino
read_wire();
// Print results to the display.
lcd_refresh();
// Remember current temperature for next run.
tempClast = tempC;
}
@ -86,9 +97,9 @@ void lcd_refresh() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(lux);
lcd.print(" Lux / ");
lcd.print("Lux/");
lcd.print(photo);
lcd.print(" Pr");
lcd.print((char)0b11110100); // Thats the sign for Ohm but the value is not Ohm. I use this sign to represent the photo resister value
lcd.setCursor(0, 1);
lcd.print(tempC);
lcd.print((char)223); // ASCII code 223 = "°"