Dezibot 4
MultiColorLight.cpp
Go to the documentation of this file.
1 #include "MultiColorLight.h"
2 
3 MultiColorLight::MultiColorLight():rgbLeds(ledAmount,ledPin){
4 
5 };
6 
8  rgbLeds.begin();
9  this->turnOffLed();
10 };
11 
12 void MultiColorLight::setLed(uint8_t index , uint32_t color){
13  if (index > ledAmount-1){
14  //TODO: logging
15  }
16  rgbLeds.setPixelColor(index, normalizeColor(color));
17  rgbLeds.show();
18 };
19 
20 
22  switch (leds){
23  case TOP_LEFT:
25  case TOP_RIGHT:
27  case BOTTOM:
29  case TOP:
30  for (int index = 0; index<2; index++){
32  }break;
33  case ALL:
34  for (int index = 0; index<ledAmount; index++){
36  }break;
37  default:
38  //TODO logging
39  break;
40  }
41 
42 };
43 
44 void MultiColorLight::setLed(leds leds, uint8_t red, uint8_t green, uint8_t blue){
46 };
47 
48 
51 };
52 
53 void MultiColorLight::setTopLeds(uint8_t red, uint8_t green, uint8_t blue){
55 };
56 
57 void MultiColorLight::blink(uint16_t amount,uint32_t color, leds leds, uint32_t interval){
58  for(uint16_t index = 0; index < amount;index++){
60  vTaskDelay(interval);
62  vTaskDelay(interval);
63  }
64 };
65 
67  switch (leds){
68  case TOP_LEFT:
69  MultiColorLight::setLed(1,0);break;
70  case TOP_RIGHT:
71  MultiColorLight::setLed(0,0);break;
72  case BOTTOM:
73  MultiColorLight::setLed(2,0);break;
74  case TOP:
75  for (int index = 0; index<2; index++){
76  MultiColorLight::setLed(index,0);
77  }break;
78  case ALL:
79  for (int index = 0; index<3; index++){
80  MultiColorLight::setLed(index,0);
81  }break;
82  default:
83  //TODO logging
84  break;
85  }
86 };
87 
88 uint32_t MultiColorLight::color(uint8_t r, uint8_t g, uint8_t b){
89  return rgbLeds.Color(r,g,b);
90 };
91 
92 //PRIVATE
93 uint32_t MultiColorLight::normalizeColor(uint32_t color,uint8_t maxBrightness){
94  uint8_t red = (color&0x00FF0000)>>16;
95  uint8_t green = (color&0x0000FF00)>>8;
96  uint8_t blue = (color&0x000000FF);
97  if (red > maxBrightness){
98  red = maxBrightness;
99  }
100  if(green > maxBrightness-70){
101  green = maxBrightness-70;
102  }
103  if(blue > maxBrightness-50){
104  blue = maxBrightness-50;
105  }
106  return MultiColorLight::color(red,green,blue);
107 }
MultiColorLight::turnOffLed
void turnOffLed(leds leds=ALL)
turn off the given leds
Definition: MultiColorLight.cpp:66
color
color
Definition: ColorDetection.h:48
MultiColorLight::MultiColorLight
MultiColorLight()
Definition: MultiColorLight.cpp:3
BOTTOM
@ BOTTOM
Definition: MultiColorLight.h:23
TOP
@ TOP
Definition: MultiColorLight.h:24
MultiColorLight::color
uint32_t color(uint8_t r, uint8_t g, uint8_t b)
wrapper to calulate the used colorformat from a rgb-value
Definition: MultiColorLight.cpp:88
MultiColorLight::blink
void blink(uint16_t amount, uint32_t color=0x00006400, leds leds=TOP, uint32_t interval=1000)
Let LEDs blink, returns after all blinks were executed.
Definition: MultiColorLight.cpp:57
ALL
@ ALL
Definition: MultiColorLight.h:25
MultiColorLight::maxBrightness
static const uint8_t maxBrightness
Definition: MultiColorLight.h:32
TOP_LEFT
@ TOP_LEFT
Definition: MultiColorLight.h:21
MultiColorLight::rgbLeds
Adafruit_NeoPixel rgbLeds
Definition: MultiColorLight.h:33
leds
leds
Describes combinations of leds on the Dezibot. With the Robot in Front of you, when the robot drives ...
Definition: MultiColorLight.h:20
MultiColorLight.h
This component controls the ability to show multicolored light, using the RGB-LEDs.
MultiColorLight::setLed
void setLed(uint8_t index, uint32_t color)
Set the specified led to the passed color.
Definition: MultiColorLight.cpp:12
MultiColorLight::setTopLeds
void setTopLeds(uint32_t color)
sets the two leds on the top of the robot to the specified color
Definition: MultiColorLight.cpp:49
MultiColorLight::begin
void begin(void)
initialize the multicolor component
Definition: MultiColorLight.cpp:7
TOP_RIGHT
@ TOP_RIGHT
Definition: MultiColorLight.h:22
MultiColorLight::ledAmount
static const uint16_t ledAmount
Definition: MultiColorLight.h:30