chg: dev: first version of multiColorLight implemeted

This commit is contained in:
hhau 2023-11-26 11:28:17 +01:00
parent e72595e739
commit 1b330e1520
5 changed files with 115 additions and 87 deletions

View File

@ -1,13 +1,16 @@
#include <Dezibot.h>
#define GPIO_LED 48
Dezibot dezibot = Dezibot();
const uint8_t MYFOO = 10;
void setup() {
dezibot.begin();
}
void loop() {
dezibot.multiColorLight.setLed(TOP_LEFT,0x000000FF);
dezibot.multiColorLight.setLed(TOP_RIGHT,dezibot.multiColorLight.color(0,100,0));
dezibot.multiColorLight.blink(10,0x00FF0000,BOTTOM,500);
delay(1000);
}

View File

@ -1,82 +1,20 @@
//
// Created by Anton Jacker on 24.11.23.
//
/**
* @file Dezibot.cpp
* @author Anton Jacker, Hans Haupt, Saskia Duebener
* @brief
* @version 0.1
* @date 2023-11-26
*
* @copyright Copyright (c) 2023
*
*/
#include "Dezibot.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_SSD1306.h>
Dezibot::Dezibot():multiColorLight(){
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define GPIO_LED 48
};
void Dezibot::begin(void) {
Adafruit_NeoPixel ledStrip = Adafruit_NeoPixel(3, GPIO_LED, NEO_GRB + NEO_KHZ800);
Wire.begin(1, 2);
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println("SSD1306 allocation failed");
for (;;); // Don't proceed, loop forever
}
display.display();
vTaskDelay(2000);
display.clearDisplay();
vTaskDelay(2000);
// Draw a single pixel in white
display.drawPixel(10, 10, SSD1306_WHITE);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
vTaskDelay(2000);
Serial.begin(9600);
Serial.println("start");
vTaskDelay(1000);
while (1) {
/* Blink off (output low) */
ledStrip.setPixelColor(1, ledStrip.Color(100, 0, 0));
ledStrip.show(); // Aktualisiere die Farbe des Pixels
vTaskDelay(1000);
/* Blink on (output high) */
ledStrip.setPixelColor(1, ledStrip.Color(0, 0, 0));
ledStrip.show(); // Aktualisiere die Farbe des Pixels
vTaskDelay(1000);
struct timeval tv_now;
gettimeofday(&tv_now, NULL);
int64_t time_us = (int64_t) tv_now.tv_sec * 1000000L + (int64_t) tv_now.tv_usec;
Serial.println(time_us);
display.clearDisplay();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 0);
display.println(F("scroll"));
display.display(); // Show initial text
vTaskDelay(1000);
}
}
multiColorLight.begin();
};

View File

@ -21,6 +21,7 @@ class Dezibot {
protected:
public:
Dezibot();
Motion motion;
LightDetection lightDetection;
ColorDetection colorDetection;

View File

@ -1,31 +1,97 @@
#include "MultiColorLight.h"
void MultiColorLight::begin(void){
MultiColorLight::MultiColorLight():rgbLeds(ledAmount,ledPin){
};
void MultiColorLight::setLed(uint8_t index , uint32_t color){
void MultiColorLight::begin(void){
rgbLeds.begin();
};
void MultiColorLight::setLed(uint8_t index , uint32_t color){
if (index > ledAmount-1){
//TODO: logging
}
rgbLeds.setPixelColor(index, normalizeColor(color));
rgbLeds.show();
};
void MultiColorLight::setLed(leds leds, uint32_t color){
switch (leds){
case TOP_LEFT:
MultiColorLight::setLed(0,color);break;
case TOP_RIGHT:
MultiColorLight::setLed(1,color);break;
case BOTTOM:
MultiColorLight::setLed(2,color);break;
case TOP:
for (int index = 0; index<2; index++){
MultiColorLight::setLed(index,color);
}break;
case ALL:
for (int index = 0; index<3; index++){
MultiColorLight::setLed(index,color);
}break;
default:
//TODO logging
break;
}
};
void MultiColorLight::setTopLeds(uint32_t color){
MultiColorLight::setLed(TOP,color);
};
void MultiColorLight::blink(uint16_t amount,uint32_t color, leds leds, uint32_t interval){
for(uint16_t index = 0; index < amount;index++){
MultiColorLight::setLed(leds, color);
vTaskDelay(interval);
MultiColorLight::turnOff(leds);
vTaskDelay(interval);
}
};
void MultiColorLight::turnOff(leds leds){
switch (leds){
case TOP_LEFT:
MultiColorLight::setLed(0,0);break;
case TOP_RIGHT:
MultiColorLight::setLed(1,0);break;
case BOTTOM:
MultiColorLight::setLed(2,0);break;
case TOP:
for (int index = 0; index<2; index++){
MultiColorLight::setLed(index,0);
}break;
case ALL:
rgbLeds.clear();break;
default:
//TODO logging
break;
}
};
uint32_t MultiColorLight::color(uint8_t r, uint8_t g, uint8_t b){
return 0;
};
return rgbLeds.Color(r,g,b);
};
//PRIVATE
uint32_t MultiColorLight::normalizeColor(uint32_t color,uint8_t maxBrightness){
uint8_t red = (color&0x00FF0000)>>16;
uint8_t green = (color&0x0000FF00)>>8;
uint8_t blue = (color&0x000000FF);
if (red > maxBrightness){
red = maxBrightness;
}
if(green > maxBrightness){
green = maxBrightness;
}
if(blue > maxBrightness){
blue = maxBrightness;
}
return MultiColorLight::color(red,green,blue);
}

View File

@ -26,8 +26,14 @@ enum leds{
};
class MultiColorLight{
protected:
static const uint16_t ledAmount = 3;
static const int16_t ledPin = 48;
static const uint8_t maxBrightness = 100;
Adafruit_NeoPixel rgbLeds;
public:
MultiColorLight();
/**
* @brief initialize the multicolor component
*
@ -94,7 +100,21 @@ public:
* component, and BB is the blue component.
*/
uint32_t color(uint8_t r, uint8_t g, uint8_t b);
private:
/**
* @brief normalizes every component of color to not exeed the maxBrightness
*
* @param color A 32-bit unsigned integer representing the color in the format
* 0x00RRGGBB, where RR is the red component, GG is the green
* component, and BB is the blue component.
* @param maxBrigthness maximal level of brightness that is allowed for each color
* @return uint32_t A 32-bit unsigned integer representing the color in the format
* 0x00RRGGBB, where RR is the red component, GG is the green
* component, and BB is the blue component. Where each component can be
* between 0 - maxBrightness
*/
uint32_t normalizeColor(uint32_t color, uint8_t maxBrigthness=maxBrightness);
};
#endif //MultiColorLight_h