Advertisement
Guest User

Untitled

a guest
Mar 30th, 2021
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "SparkFun_VEML6030_Ambient_Light_Sensor.h"
  3.  
  4. #define AL_ADDR 0x48
  5.  
  6. #define AL_ADDR2 0x10
  7.  
  8. SparkFun_Ambient_Light light(AL_ADDR);
  9. SparkFun_Ambient_Light light2(AL_ADDR2);
  10.  
  11. // Possible values: .125, .25, 1, 2
  12. // Both .125 and .25 should be used in most cases except darker rooms.
  13. // A gain of 2 should only be used if the sensor will be covered by a dark
  14. // glass.
  15. float gain = .125;
  16.  
  17. // Possible integration times in milliseconds: 800, 400, 200, 100, 50, 25
  18. // Higher times give higher resolutions and should be used in darker light.
  19. int time = 50;
  20. long luxVal = 0;
  21. long luxVal2 = 0;
  22. long loopcount = 0;
  23.  
  24. void setup(){
  25.  
  26. Wire.begin();
  27. Serial.begin(115200);
  28.  
  29. if(light.begin())
  30. Serial.println("Ready to sense some light!");
  31. else
  32. Serial.println("Could not communicate with the sensor!");
  33.  
  34. if(light2.begin())
  35. Serial.println("Ready to sense some light!");
  36. else
  37. Serial.println("Could not communicate with the sensor!");
  38.  
  39. // Again the gain and integration times determine the resolution of the lux
  40. // value, and give different ranges of possible light readings. Check out
  41. // hoookup guide for more info.
  42. light.setGain(gain);
  43. light.setIntegTime(time);
  44. light2.setGain(gain);
  45. light2.setIntegTime(time);
  46.  
  47. Serial.println("Reading settings...");
  48. Serial.print("Gain: ");
  49. float gainVal = light.readGain();
  50. Serial.print(gainVal, 3);
  51. Serial.print(" Integration Time: ");
  52. int timeVal = light.readIntegTime();
  53. Serial.println(timeVal);
  54. pinMode(LED_BUILTIN, OUTPUT);
  55.  
  56. }
  57.  
  58. void loop(){
  59.  
  60. luxVal = light.readLight();
  61. luxVal2 = light2.readLight();
  62. Serial.print("Ambient Light Reading: ");
  63. Serial.print(luxVal);
  64. Serial.println(" Lux");
  65. Serial.print("Ambient Light 2 Reading: ");
  66. Serial.print(luxVal2);
  67. Serial.println(" Lux");
  68. if((loopcount%2) == 1){
  69. digitalWrite(LED_BUILTIN, HIGH);
  70. } else {
  71. digitalWrite(LED_BUILTIN, LOW);
  72. }
  73. loopcount ++;
  74. Serial.print("Iteration: ");
  75. Serial.println(loopcount);
  76. delay(200);
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement