Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include "SparkFun_VEML6030_Ambient_Light_Sensor.h"
- #define AL_ADDR 0x48
- #define AL_ADDR2 0x10
- SparkFun_Ambient_Light light(AL_ADDR);
- SparkFun_Ambient_Light light2(AL_ADDR2);
- // Possible values: .125, .25, 1, 2
- // Both .125 and .25 should be used in most cases except darker rooms.
- // A gain of 2 should only be used if the sensor will be covered by a dark
- // glass.
- float gain = .125;
- // Possible integration times in milliseconds: 800, 400, 200, 100, 50, 25
- // Higher times give higher resolutions and should be used in darker light.
- int time = 50;
- long luxVal = 0;
- long luxVal2 = 0;
- long loopcount = 0;
- void setup(){
- Wire.begin();
- Serial.begin(115200);
- if(light.begin())
- Serial.println("Ready to sense some light!");
- else
- Serial.println("Could not communicate with the sensor!");
- if(light2.begin())
- Serial.println("Ready to sense some light!");
- else
- Serial.println("Could not communicate with the sensor!");
- // Again the gain and integration times determine the resolution of the lux
- // value, and give different ranges of possible light readings. Check out
- // hoookup guide for more info.
- light.setGain(gain);
- light.setIntegTime(time);
- light2.setGain(gain);
- light2.setIntegTime(time);
- Serial.println("Reading settings...");
- Serial.print("Gain: ");
- float gainVal = light.readGain();
- Serial.print(gainVal, 3);
- Serial.print(" Integration Time: ");
- int timeVal = light.readIntegTime();
- Serial.println(timeVal);
- pinMode(LED_BUILTIN, OUTPUT);
- }
- void loop(){
- luxVal = light.readLight();
- luxVal2 = light2.readLight();
- Serial.print("Ambient Light Reading: ");
- Serial.print(luxVal);
- Serial.println(" Lux");
- Serial.print("Ambient Light 2 Reading: ");
- Serial.print(luxVal2);
- Serial.println(" Lux");
- if((loopcount%2) == 1){
- digitalWrite(LED_BUILTIN, HIGH);
- } else {
- digitalWrite(LED_BUILTIN, LOW);
- }
- loopcount ++;
- Serial.print("Iteration: ");
- Serial.println(loopcount);
- delay(200);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement