Created
September 15, 2018 11:43
-
-
Save xxlukas42/feb445f565be29d705fda2ef6f794c73 to your computer and use it in GitHub Desktop.
Ambient light shield and LED shield for D1 Pro Mini
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************* | |
Wemos Lolin D1 PRO (ESP8266) | |
Basic demo | |
by Petr Lukas | |
*************************************************************/ | |
// Install Adafruit_NeoPixel library https://github.com/adafruit/Adafruit_NeoPixel first | |
#include <Adafruit_NeoPixel.h> | |
#include <Wire.h> | |
// Install [claws/BH1750 Library](https://github.com/claws/BH1750) first | |
#include <BH1750.h> | |
#define PIN D4 | |
#define LED_NUM 7 | |
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_NUM, PIN, NEO_GRB + NEO_KHZ800); | |
BH1750 lightMeter(0x23); | |
void setup() { | |
Serial.begin(9600); | |
leds.begin(); // This initializes the NeoPixel library. | |
Wire.begin(); | |
if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) { | |
Serial.println(F("BH1750 Advanced begin")); | |
} | |
else { | |
Serial.println(F("Error initialising BH1750")); | |
} | |
} | |
void led_set(uint8 R, uint8 G, uint8 B) { | |
for (int i = 0; i < LED_NUM; i++) { | |
leds.setPixelColor(i, leds.Color(R, G, B)); | |
leds.show(); | |
delay(10); | |
} | |
} | |
void loop() { | |
uint16_t lux = lightMeter.readLightLevel(); | |
Serial.print("Light: "); | |
Serial.print(lux); | |
Serial.println(" lx"); | |
// Tune sensitivity/response of LED shield by your needs. By default it reacts for changes between 0 and 255 lx | |
int intens = 255 - lux; | |
if(intens > 255) intens = 255; | |
if(intens < 0) intens = 0; | |
led_set(intens, 0, 0); // Red color by default | |
delay(200); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment