Dezibot 4
ColorDetection.cpp
Go to the documentation of this file.
1 #include "ColorDetection.h"
2 
4  const VEML_CONFIG DEFAULT_CONFIG = VEML_CONFIG {
5  .mode = AUTO,
6  .enabled = true,
7  .exposureTime = MS320 };
8  ColorDetection::configure(DEFAULT_CONFIG);
9 };
10 
12  rgbwSensor.begin();
13 
14  uint8_t configuration = 0;
15 
16  switch(config.exposureTime) {
17  case MS40:
18  configuration += VEML6040_IT_40MS;
19  break;
20  case MS80:
21  configuration += VEML6040_IT_80MS;
22  break;
23  case MS160:
24  configuration += VEML6040_IT_160MS;
25  break;
26  case MS320:
27  configuration += VEML6040_IT_320MS;
28  break;
29  case MS640:
30  configuration += VEML6040_IT_640MS;
31  break;
32  case MS1280:
33  configuration += VEML6040_IT_1280MS;
34  break;
35  }
36 
37  configuration += (config.mode == MANUAL) ? VEML6040_AF_FORCE : VEML6040_AF_AUTO;
38  configuration += config.enabled ? VEML6040_SD_ENABLE : VEML6040_SD_DISABLE;
39 
40  rgbwSensor.setConfiguration(configuration);
41 };
42 
44  switch(color) {
45  case VEML_RED:
46  return rgbwSensor.getRed();
47  case VEML_GREEN:
48  return rgbwSensor.getGreen();
49  case VEML_BLUE:
50  return rgbwSensor.getBlue();
51  case VEML_WHITE:
52  return rgbwSensor.getWhite();
53  default:
54  Serial.println("Color is not supported by the sensor");
55  return 0;
56  }
57 };
58 
60  return rgbwSensor.getAmbientLight();
61 };
MS80
@ MS80
Definition: ColorDetection.h:25
VEML_WHITE
@ VEML_WHITE
Definition: ColorDetection.h:52
VEML_CONFIG::enabled
bool enabled
Definition: ColorDetection.h:42
MS640
@ MS640
Definition: ColorDetection.h:28
color
color
Definition: ColorDetection.h:48
MANUAL
@ MANUAL
Definition: ColorDetection.h:34
MS160
@ MS160
Definition: ColorDetection.h:26
ColorDetection::getColorValue
uint16_t getColorValue(color color)
Get color value of RGBW sensor.
Definition: ColorDetection.cpp:43
ColorDetection::beginAutoMode
void beginAutoMode()
Start RBGW sensor with default configuration.
Definition: ColorDetection.cpp:3
MS320
@ MS320
Definition: ColorDetection.h:27
VEML_RED
@ VEML_RED
Definition: ColorDetection.h:49
VEML_GREEN
@ VEML_GREEN
Definition: ColorDetection.h:50
ColorDetection::getAmbientLight
float getAmbientLight()
Get the ambient light in lux.
Definition: ColorDetection.cpp:59
VEML_CONFIG::exposureTime
duration exposureTime
Definition: ColorDetection.h:45
VEML_CONFIG
Definition: ColorDetection.h:37
ColorDetection.h
AUTO
@ AUTO
Definition: ColorDetection.h:33
ColorDetection::configure
void configure(VEML_CONFIG config)
Begin RGBW sensor with passed configuration values.
Definition: ColorDetection.cpp:11
MS40
@ MS40
Definition: ColorDetection.h:24
VEML_BLUE
@ VEML_BLUE
Definition: ColorDetection.h:51
MS1280
@ MS1280
Definition: ColorDetection.h:29
ColorDetection::rgbwSensor
VEML6040 rgbwSensor
Definition: ColorDetection.h:86
VEML_CONFIG::mode
vemlMode mode
Definition: ColorDetection.h:39