diff --git a/example/example.ino b/example/example.ino new file mode 100644 index 0000000..ff3b7ec --- /dev/null +++ b/example/example.ino @@ -0,0 +1,12 @@ +#include + + + +Dezibot dezibot = Dezibot(); + +void setup() { + dezibot.begin(); +} + +void loop() { +} diff --git a/src/Dezibot.cpp b/src/Dezibot.cpp index bfbeb58..610479e 100644 --- a/src/Dezibot.cpp +++ b/src/Dezibot.cpp @@ -1,29 +1,18 @@ -/** - * @file Dezibot.cpp - * @author Anton Jacker, Hans Haupt, Saskia Duebener - * @brief - * @version 0.1 - * @date 2023-11-26 - * - * @copyright Copyright (c) 2023 - * - */ +// +// Created by Anton Jacker on 24.11.23. +// #include "Dezibot.h" #include -#include + +#include -Dezibot::Dezibot():multiColorLight(),motionDetection(){ #define GPIO_LED 48 void Dezibot::begin(void) { - infraredLight.begin(); - motion.begin(); - multiColorLight.begin(); - lightDetection.begin(); - motionDetection.begin(); -}; + +} diff --git a/src/colorDetection/ColorDetection.cpp b/src/colorDetection/ColorDetection.cpp new file mode 100644 index 0000000..6caf26b --- /dev/null +++ b/src/colorDetection/ColorDetection.cpp @@ -0,0 +1,84 @@ +#include "ColorDetection.h" + +void ColorDetection::begin(void){ + Wire.begin(I2C_MASTER_SDA_IO,I2C_MASTER_SCL_IO); + ColorDetection::configure(VEML_CONFIG{.mode = AUTO,.enabled = true,.exposureTime=MS40}); +}; +void ColorDetection::configure(VEML_CONFIG config){ + uint8_t configRegister = 0; + switch(config.exposureTime) + { + case MS40: + configRegister = 0x00;break; + case MS80: + configRegister = 0x01;break; + case MS160: + configRegister = 0x02;break; + case MS320: + configRegister = 0x03;break; + case MS640: + configRegister = 0x04;break; + case MS1280: + configRegister = 0x05;break; + } + configRegister = configRegister << 4; + if(config.mode == MANUAL) + { + configRegister = configRegister | (0x01<<1); + } + if(!config.enabled) + { + configRegister = configRegister | 1; + } + ColorDetection::writeDoubleRegister(CMD_CONFIG,(uint16_t)configRegister); +}; + +uint16_t ColorDetection::getColorValue(color color){ + + switch(color) + { + case RED: + return readDoubleRegister(REG_RED); + break; + case GREEN: + return readDoubleRegister(REG_GREEN); + break; + case BLUE: + return readDoubleRegister(REG_BLUE); + break; + case WHITE: + return readDoubleRegister(REG_WHITE); + break; + default: + Serial.println("Color is not supported by the sensor"); + return 0; + } +}; + +uint16_t ColorDetection::readDoubleRegister(uint8_t regAddr){ + uint16_t result = 0; + Wire.beginTransmission(VEML_ADDR); + Wire.write(regAddr); + if(Wire.endTransmission() != 0){ + Serial.printf("Reading Register %d failed",regAddr); + } + Wire.requestFrom(VEML_ADDR,2); + uint8_t offset = 0; + while(Wire.available()){ + result = result << 8; + result = result | (Wire.read()<>8)&0x00FF)); + if(Wire.endTransmission() != 0){ + Serial.printf("Reading Register %d failed",regAddr); + } +}; \ No newline at end of file diff --git a/src/colorDetection/ColorDetection.h b/src/colorDetection/ColorDetection.h index b89e6d5..a8d42e2 100644 --- a/src/colorDetection/ColorDetection.h +++ b/src/colorDetection/ColorDetection.h @@ -1,7 +1,57 @@ #ifndef ColorDetection_h #define ColorDetection_h +#include +#include +#include +//Definitions for I2c +#define I2C_MASTER_SCL_IO 2 /*!< GPIO number used for I2C master clock */ +#define I2C_MASTER_SDA_IO 1 /*!< GPIO number used for I2C master data */ +//Chipadress of the VEML6040 +#define VEML_ADDR 0x10 /*!< Slave address of the MPU9250 sensor */ + +//CMDCodes for communicate with the VEML6040 +#define CMD_CONFIG 0x00 +#define REG_RED 0x08 +#define REG_GREEN 0x09 +#define REG_BLUE 0x0A +#define REG_WHITE 0x0B + + +enum duration{ + MS40, + MS80, + MS160, + MS320, + MS640, + MS1280 +}; + +enum vemlMode{ + AUTO, + MANUAL +}; + +struct VEML_CONFIG{ + vemlMode mode; + bool enabled; + duration exposureTime; +}; + + +enum color{ + RED, + GREEN, + BLUE, + WHITE +}; class ColorDetection{ - +public: + void begin(void); + void configure(VEML_CONFIG config); + uint16_t getColorValue(color color); +protected: + uint16_t readDoubleRegister(uint8_t regAddr); + void writeDoubleRegister(uint8_t regAddr, uint16_t data); }; #endif //ColorDetection_h \ No newline at end of file