forked from NAG-IoT/odevzdani
Nahrát soubory do „03“
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 125 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
@@ -0,0 +1,42 @@
|
|||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <BH1750.h>
|
||||||
|
|
||||||
|
#define ledka D0
|
||||||
|
|
||||||
|
BH1750 lightMeter;
|
||||||
|
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
pinMode(ledka, OUTPUT);
|
||||||
|
|
||||||
|
// Initialize the I2C bus (BH1750 library doesn't do this automatically)
|
||||||
|
Wire.begin();
|
||||||
|
// On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);
|
||||||
|
|
||||||
|
lightMeter.begin();
|
||||||
|
|
||||||
|
Serial.println(F("BH1750 Test begin"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
float lux = lightMeter.readLightLevel();
|
||||||
|
Serial.print("Light: ");
|
||||||
|
Serial.print(lux);
|
||||||
|
Serial.println(" lx");
|
||||||
|
if(lux < 200)
|
||||||
|
{
|
||||||
|
digitalWrite(ledka, HIGH);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
digitalWrite(ledka, LOW);
|
||||||
|
}
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user