mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-05-21 20:11:46 +02:00
merge into 7 color detection
This commit is contained in:
commit
8d02460054
12
example/example.ino
Normal file
12
example/example.ino
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <Dezibot.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Dezibot dezibot = Dezibot();
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
dezibot.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
}
|
@ -1,29 +1,18 @@
|
|||||||
/**
|
//
|
||||||
* @file Dezibot.cpp
|
// Created by Anton Jacker on 24.11.23.
|
||||||
* @author Anton Jacker, Hans Haupt, Saskia Duebener
|
//
|
||||||
* @brief
|
|
||||||
* @version 0.1
|
|
||||||
* @date 2023-11-26
|
|
||||||
*
|
|
||||||
* @copyright Copyright (c) 2023
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "Dezibot.h"
|
#include "Dezibot.h"
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Wire.h>
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
|
||||||
Dezibot::Dezibot():multiColorLight(),motionDetection(){
|
|
||||||
|
|
||||||
|
|
||||||
#define GPIO_LED 48
|
#define GPIO_LED 48
|
||||||
|
|
||||||
void Dezibot::begin(void) {
|
void Dezibot::begin(void) {
|
||||||
infraredLight.begin();
|
|
||||||
motion.begin();
|
}
|
||||||
multiColorLight.begin();
|
|
||||||
lightDetection.begin();
|
|
||||||
motionDetection.begin();
|
|
||||||
};
|
|
||||||
|
84
src/colorDetection/ColorDetection.cpp
Normal file
84
src/colorDetection/ColorDetection.cpp
Normal file
@ -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()<<offset);
|
||||||
|
offset = offset + 8;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
void ColorDetection::writeDoubleRegister(uint8_t regAddr, uint16_t data){
|
||||||
|
//erst low dann high
|
||||||
|
Wire.beginTransmission(VEML_ADDR);
|
||||||
|
Wire.write(regAddr);
|
||||||
|
Wire.write((uint8_t)(data&0x00FF));
|
||||||
|
Wire.write((uint8_t)((data>>8)&0x00FF));
|
||||||
|
if(Wire.endTransmission() != 0){
|
||||||
|
Serial.printf("Reading Register %d failed",regAddr);
|
||||||
|
}
|
||||||
|
};
|
@ -1,7 +1,57 @@
|
|||||||
#ifndef ColorDetection_h
|
#ifndef ColorDetection_h
|
||||||
#define ColorDetection_h
|
#define ColorDetection_h
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
//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{
|
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
|
#endif //ColorDetection_h
|
Loading…
x
Reference in New Issue
Block a user