Dezibot 4
Loading...
Searching...
No Matches
ColorDetection.cpp
Go to the documentation of this file.
1#include "ColorDetection.h"
2
4 ColorDetection::configure(VEML_CONFIG{.mode = AUTO,.enabled = true,.exposureTime=MS40});
5};
7 uint8_t configRegister = 0;
8 switch(config.exposureTime)
9 {
10 case MS40:
11 configRegister = 0x00;break;
12 case MS80:
13 configRegister = 0x01;break;
14 case MS160:
15 configRegister = 0x02;break;
16 case MS320:
17 configRegister = 0x03;break;
18 case MS640:
19 configRegister = 0x04;break;
20 case MS1280:
21 configRegister = 0x05;break;
22 }
23 configRegister = configRegister << 4;
24 if(config.mode == MANUAL)
25 {
26 configRegister = configRegister | (0x01<<1);
27 }
28 if(!config.enabled)
29 {
30 configRegister = configRegister | 1;
31 }
32 ColorDetection::writeDoubleRegister(CMD_CONFIG,(uint16_t)configRegister);
33};
34
36
37 switch(color)
38 {
39 case VEML_RED:
41 break;
42 case VEML_GREEN:
44 break;
45 case VEML_BLUE:
47 break;
48 case VEML_WHITE:
50 break;
51 default:
52 Serial.println("Color is not supported by the sensor");
53 return 0;
54 }
55};
56
57uint16_t ColorDetection::readDoubleRegister(uint8_t regAddr){
58 uint16_t result = 0;
59 Wire.beginTransmission(VEML_ADDR);
60 Wire.write(regAddr);
61 if(Wire.endTransmission() != 0){
62 Serial.printf("Reading Register %d failed",regAddr);
63 }
64 Wire.requestFrom(VEML_ADDR,2);
65 uint8_t offset = 0;
66 while(Wire.available()){
67 result = result << 8;
68 result = result | (Wire.read()<<offset);
69 offset = offset + 8;
70 }
71 return result;
72};
73
74void ColorDetection::writeDoubleRegister(uint8_t regAddr, uint16_t data){
75 //erst low dann high
76 Wire.beginTransmission(VEML_ADDR);
77 Wire.write(regAddr);
78 Wire.write((uint8_t)(data&0x00FF));
79 Wire.write((uint8_t)((data>>8)&0x00FF));
80 if(Wire.endTransmission() != 0){
81 Serial.printf("Reading Register %d failed",regAddr);
82 }
83};
color
@ VEML_GREEN
@ VEML_RED
@ VEML_BLUE
@ VEML_WHITE
#define REG_RED
@ MS320
@ MS160
@ MS1280
@ MS40
@ MS80
@ MS640
#define CMD_CONFIG
#define REG_GREEN
#define VEML_ADDR
#define REG_WHITE
#define REG_BLUE
@ MANUAL
@ AUTO
uint16_t getColorValue(color color)
uint16_t readDoubleRegister(uint8_t regAddr)
void configure(VEML_CONFIG config)
void writeDoubleRegister(uint8_t regAddr, uint16_t data)
duration exposureTime
vemlMode mode