Last active
February 3, 2019 09:35
-
-
Save tg44/66525472f69718d28224f4d0278112f0 to your computer and use it in GitHub Desktop.
Wemos D1 mini TSL2561
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
#include <Wire.h> | |
#include <Adafruit_Sensor.h> | |
#include <Adafruit_TSL2561_U.h> | |
#include <SPI.h> | |
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); | |
void setup(void) { | |
Serial.begin(9600); | |
Serial.println(""); | |
Serial.println("Light Sensor Test"); | |
Serial.println(""); | |
if(!tsl.begin()) { | |
Serial.print("No TSL2561 detected"); | |
while(1); | |
} | |
tsl.enableAutoRange(true); | |
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
void loop(void) { | |
sensors_event_t event; | |
tsl.getEvent(&event); | |
if (event.light) { | |
Serial.print(event.light); | |
Serial.println(" lux"); | |
if(event.light < 15) { | |
digitalWrite(LED_BUILTIN, LOW); | |
} else { | |
digitalWrite(LED_BUILTIN, HIGH); | |
} | |
} else { | |
Serial.println("Sensor overload"); | |
} | |
delay(500); | |
} |
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
#include <Wire.h> | |
#include <Adafruit_Sensor.h> | |
#include <Adafruit_TSL2561_U.h> | |
#include <SPI.h> | |
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); | |
void setup(void) { | |
Serial.begin(9600); | |
Serial.println(""); | |
Serial.println("Light Sensor Test"); | |
Serial.println(""); | |
/* Initialise the sensor */ | |
if(!tsl.begin()) { | |
Serial.print("No TSL2561 detected"); | |
while(1); | |
} | |
tsl.enableAutoRange(true); | |
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); | |
} | |
void loop(void) | |
{ | |
/* Get a new sensor event */ | |
sensors_event_t event; | |
tsl.getEvent(&event); | |
/* Display the results (light is measured in lux) */ | |
if (event.light) { | |
Serial.print(event.light); | |
Serial.println(" lux"); | |
} | |
else { | |
Serial.println("Sensor overload"); | |
} | |
delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment