~alienagain/Navecita

Navecita/code/read_uva.ino -rw-r--r-- 1.6 KiB
6ec9520c — alien adding code for UVA reading 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <Wire.h>
#include "Adafruit_VEML6075.h"

Adafruit_VEML6075 uv = Adafruit_VEML6075();

void setup() {
  Serial.begin(115200);
  //Serial.println("VEML6075 Full Test");
  if (! uv.begin()) {
    Serial.println("Failed to communicate with VEML6075 sensor, check wiring?");
  }
  //Serial.println("Found VEML6075 sensor");

  // Set the integration constant
  uv.setIntegrationTime(VEML6075_100MS);
  // Get the integration constant and print it!
  //Serial.print("Integration time set to ");
  switch (uv.getIntegrationTime()) {
    //case VEML6075_50MS: Serial.print("50"); break;
    //case VEML6075_100MS: Serial.print("100"); break;
    //case VEML6075_200MS: Serial.print("200"); break;
    //case VEML6075_400MS: Serial.print("400"); break;
    //case VEML6075_800MS: Serial.print("800"); break;
  }
  //Serial.println("ms");

  // Set the high dynamic mode
  uv.setHighDynamic(true);
  // Get the mode
  if (uv.getHighDynamic()) {
   // Serial.println("High dynamic reading mode");
  } else {
    //Serial.println("Normal dynamic reading mode");
  }

  // Set the mode
  uv.setForcedMode(false);
  // Get the mode
  if (uv.getForcedMode()) {
    //Serial.println("Forced reading mode");
  } else {
    //Serial.println("Continuous reading mode");
  }

  // Set the calibration coefficients
  uv.setCoefficients(2.22, 1.33,  // UVA_A and UVA_B coefficients
                     2.95, 1.74,  // UVB_C and UVB_D coefficients
                     0.001461, 0.002591); // UVA and UVB responses
}


void loop() {
  Serial.println(abs(uv.readUVA()));
  //Serial.println(uv.readUVB());
  //Serial.print("UV Index reading: "); Serial.println(uv.readUVI());

  delay(3000);
}