Skip to content
Snippets Groups Projects
Commit 89a967ec authored by Orhan-Timo Altan's avatar Orhan-Timo Altan
Browse files

v2.0 Angepasst an die Konvention der thk_libs

parent e43d8b7d
No related branches found
No related tags found
No related merge requests found
# **LED strip Funktionen** # **LED strip controller**
Eine Klasse für die Initializierung und Steuerung von LED-Streifen Eine Klasse für die Initializierung und Steuerung von LED-Streifen
...@@ -13,12 +13,12 @@ Zur Verwendung siehe zunächst das Beispiel `ledshow.ino` ...@@ -13,12 +13,12 @@ Zur Verwendung siehe zunächst das Beispiel `ledshow.ino`
**Einbinden der Bibliothek:** **Einbinden der Bibliothek:**
```Arduino ```Arduino
#include <ledstrip.h> #include <thk_ledstrip_controller.h>
``` ```
**Instanziieren:** **Instanziieren:**
```Arduino ```Arduino
Ledstrip example_strip(LED_NUMBER, PIN, brightness); thk_LedStripController example_strip(LED_NUMBER, PIN, brightness);
``` ```
- `LED_NUMBER`: Anzahl der LEDs am Streifen - `LED_NUMBER`: Anzahl der LEDs am Streifen
- `PIN`: Pin für die Steuerung des LED-Streifens - `PIN`: Pin für die Steuerung des LED-Streifens
...@@ -33,25 +33,25 @@ example_strip.clear(); ...@@ -33,25 +33,25 @@ example_strip.clear();
**Farbeinstellung der LEDs:** **Farbeinstellung der LEDs:**
```Arduino ```Arduino
example_strip.set_pixel_color(Ledstrip::Color(red, green, blue)); example_strip.set_pixel_color(thk_LedStripController::Color(red, green, blue));
``` ```
oder oder
```Arduino ```Arduino
example_strip.set_pixel_color(index, Ledstrip::Color(red, green, blue)); example_strip.set_pixel_color(index, thk_LedStripController::Color(red, green, blue));
``` ```
oder oder
```Arduino ```Arduino
example_strip.set_pixel_color(start_index, amount, Ledstrip::Color(red, green, blue)); example_strip.set_pixel_color(start_index, amount, thk_LedStripController::Color(red, green, blue));
``` ```
- `Ledstrip::Color(red, green, blue)`: Für red, green und blue Werte zwischen 0 und 255 angeben um die Helligkeit der LEDs einzustellen und somit eine Farbvariante zu generieren. - `thk_LedStripController::Color(red, green, blue)`: Für red, green und blue Werte zwischen 0 und 255 angeben um die Helligkeit der LEDs einzustellen und somit eine Farbvariante zu generieren.
- `index`: Die LED Nummerierung welche gesteuert werden soll. - `index`: Die LED Nummerierung welche gesteuert werden soll.
- `start_index`: Die LED Nummerierung von der begonnen werden soll. - `start_index`: Die LED Nummerierung von der begonnen werden soll.
- `amount`: Anzahl der LEDs, welche nach *start_index* angesteuert werden sollen. - `amount`: Anzahl der LEDs, welche nach *start_index* angesteuert werden sollen.
**Blinken & Regenbogen Effekt:** **Blinken & Regenbogen Effekt:**
```Arduino ```C++
example_strip.blink(Ledstrip::Color(red, green, blue), wait_time); example_strip.blink(thk_LedStripController::Color(red, green, blue), wait_time);
``` ```
```Arduino ```Arduino
...@@ -64,7 +64,7 @@ example_strip.rainbow_effect(wait_time); ...@@ -64,7 +64,7 @@ example_strip.rainbow_effect(wait_time);
**Lichtlauf:** **Lichtlauf:**
```Arduino ```Arduino
example_strip.running_light(wait_time, length, Ledstrip::Color(red, green, blue), direction) example_strip.running_light(wait_time, length, thk_LedStripController::Color(red, green, blue), direction)
``` ```
- `wait_time`: Die Zeit zwischen an/aus schalten und wechsel der LEDs - `wait_time`: Die Zeit zwischen an/aus schalten und wechsel der LEDs
......
#include <ledstrip.h> #include <thk_ledstrip_controller.h>
Ledstrip front_strip(6,33); // Instanziiere Objekte für jeden LED-Streifen
Ledstrip back_strip(6,37); thk_LedStripController front_strip(6,33);
Ledstrip left_strip(3, 35); thk_LedStripController back_strip(6,37);
Ledstrip rigth_strip(3, 39); thk_LedStripController left_strip(3, 35);
thk_LedStripController rigth_strip(3, 39);
bool state = true; bool state = true;
uint8_t red, green, blue; uint8_t red, green, blue;
...@@ -11,8 +12,7 @@ double start; ...@@ -11,8 +12,7 @@ double start;
void setup() void setup()
{ {
Serial.begin(115200); // Initialisierung der LED-Streifen
front_strip.init(); front_strip.init();
back_strip.init(); back_strip.init();
left_strip.init(); left_strip.init();
...@@ -22,72 +22,67 @@ void setup() ...@@ -22,72 +22,67 @@ void setup()
void loop() void loop()
{ {
start = millis(); start = millis();
while ((millis()-start) < 10000) blink(10000); // 10 Sekunden Blinken alle LEDs gleichzeitig
{ front_strip.blink(thk_LedStripController::Color(red, green, blue), 10000); // Nur der ausgewählte LED-Streifen blinkt für 10 Sekunden
if (state){
// LEDs on
red = 20;
green = 0;
blue = 30;
state=false;
}
else {
// LEDs off
red = 0;
green = 0;
blue = 0;
state=true;
}
delay(1000);
front_strip.set_pixel_color(Ledstrip::Color(red, green, blue)); delay(1000); // 1 Sekunde Pause
front_strip.show();
back_strip.set_pixel_color(Ledstrip::Color(red, green, blue));
back_strip.show();
left_strip.set_pixel_color(Ledstrip::Color(red,green, blue));
left_strip.show();
rigth_strip.set_pixel_color(Ledstrip::Color(red, green, blue));
rigth_strip.show();
}
delay(1000);
// Regenbogen Show wird für jeden LED-Streifen nacheinander ausgeführt
front_strip.rainbow_effect(10); front_strip.rainbow_effect(10);
back_strip.rainbow_effect(10); back_strip.rainbow_effect(10);
left_strip.rainbow_effect(10); left_strip.rainbow_effect(10);
rigth_strip.rainbow_effect(10); rigth_strip.rainbow_effect(10);
// Ausschalten aller LED-Streifen
front_strip.clear(); front_strip.clear();
front_strip.show(); front_strip.show();
back_strip.clear(); back_strip.clear();
back_strip.show(); back_strip.show();
left_strip.clear(); left_strip.clear();
left_strip.show(); left_strip.show();
rigth_strip.clear(); rigth_strip.clear();
rigth_strip.show(); rigth_strip.show();
delay(1000); delay(1000); // 1 Sekunde Pause
start = millis(); start = millis();
// Lichtlauf im ausgewähltem LED-Streifen für 5 Sekunden
while ((millis()-start) < 5000) while ((millis()-start) < 5000)
{ {
front_strip.running_light(50,3, Ledstrip::Color(20, 0, 0),1); front_strip.running_light(50,3, thk_LedStripController::Color(20, 0, 0),1);
front_strip.running_light(50,3, Ledstrip::Color(20, 0, 0),0); front_strip.running_light(50,3, thk_LedStripController::Color(20, 0, 0),0);
} }
delay(1000); delay(1000); // 1 Sekunde Pause
}
start = millis(); // Blink Funktion
while ((millis()-start) < 5000) void blink(int duration){
while ((millis()-start) < duration)
{ {
front_strip.running_light(50,3, Ledstrip::Color(20, 0, 0),1); if (state){
rigth_strip.running_light(50,2, Ledstrip::Color(20, 0, 0),1); // LEDs on
back_strip.running_light(50,3, Ledstrip::Color(20, 0, 0),1); red = 20;
left_strip.running_light(50,2, Ledstrip::Color(20, 0, 0),1); green = 0;
blue = 30;
state=false;
}
else {
// LEDs off
red = 0;
green = 0;
blue = 0;
state=true;
} }
delay(1000); delay(1000);
front_strip.set_pixel_color(thk_LedStripController::Color(red, green, blue));
front_strip.show();
back_strip.set_pixel_color(thk_LedStripController::Color(red, green, blue));
back_strip.show();
left_strip.set_pixel_color(thk_LedStripController::Color(red,green, blue));
left_strip.show();
rigth_strip.set_pixel_color(thk_LedStripController::Color(red, green, blue));
rigth_strip.show();
}
} }
\ No newline at end of file
#include "ledstrip.h" #include "thk_ledStrip_controller.h"
Ledstrip::Ledstrip(const uint16_t MAX_LED_NUMBER, const uint16_t DATA_PIN, uint8_t brightness): MAX_LED_NUMBER(MAX_LED_NUMBER), DATA_PIN(DATA_PIN), brightness(brightness) {} thk_LedStripController::thk_LedStripController(const uint16_t MAX_LED_NUMBER, const uint16_t DATA_PIN, uint8_t brightness): MAX_LED_NUMBER(MAX_LED_NUMBER), DATA_PIN(DATA_PIN), brightness(brightness) {}
void Ledstrip::init() { void thk_LedStripController::init() {
ptrStrip = new Adafruit_NeoPixel(MAX_LED_NUMBER, DATA_PIN, NEO_GRB + NEO_KHZ800); ptrStrip = new Adafruit_NeoPixel(MAX_LED_NUMBER, DATA_PIN, NEO_GRB + NEO_KHZ800);
ptrStrip->setBrightness(brightness); ptrStrip->setBrightness(brightness);
ptrStrip->begin(); ptrStrip->begin();
...@@ -10,38 +10,38 @@ void Ledstrip::init() { ...@@ -10,38 +10,38 @@ void Ledstrip::init() {
show(); show();
} }
void Ledstrip::clear() { void thk_LedStripController::clear() {
ptrStrip->clear(); ptrStrip->clear();
} }
void Ledstrip::set_pixel_color(uint32_t color) { void thk_LedStripController::set_pixel_color(uint32_t color) {
set_pixel_color(0, ptrStrip->numPixels(), color); set_pixel_color(0, ptrStrip->numPixels(), color);
} }
void Ledstrip::set_pixel_color(uint16_t index, uint32_t color) void thk_LedStripController::set_pixel_color(uint16_t index, uint32_t color)
{ {
ptrStrip->setPixelColor(index, color); ptrStrip->setPixelColor(index, color);
} }
void Ledstrip::set_pixel_color(uint16_t start_index, uint16_t amount, uint32_t color) { void thk_LedStripController::set_pixel_color(uint16_t start_index, uint16_t amount, uint32_t color) {
ptrStrip->fill(color, start_index, amount); ptrStrip->fill(color, start_index, amount);
} }
void Ledstrip::show() { void thk_LedStripController::show() {
ptrStrip->show(); ptrStrip->show();
} }
uint32_t Ledstrip::color_hsv(int pixelHue) { uint32_t thk_LedStripController::color_hsv(int pixelHue) {
pixelHue = ptrStrip->ColorHSV(pixelHue); pixelHue = ptrStrip->ColorHSV(pixelHue);
return pixelHue; return pixelHue;
} }
uint32_t Ledstrip::gamma(int pixelHue) { uint32_t thk_LedStripController::gamma(int pixelHue) {
pixelHue = ptrStrip->gamma32(color_hsv(pixelHue)); pixelHue = ptrStrip->gamma32(color_hsv(pixelHue));
return pixelHue; return pixelHue;
} }
void Ledstrip::blink(uint32_t color, unsigned long wait_time) { void thk_LedStripController::blink(uint32_t color, unsigned long wait_time) {
ptrStrip->clear(); ptrStrip->clear();
set_pixel_color(color); set_pixel_color(color);
ptrStrip->show(); ptrStrip->show();
...@@ -50,7 +50,7 @@ void Ledstrip::blink(uint32_t color, unsigned long wait_time) { ...@@ -50,7 +50,7 @@ void Ledstrip::blink(uint32_t color, unsigned long wait_time) {
ptrStrip->show(); ptrStrip->show();
} }
void Ledstrip::rainbow_effect(unsigned long wait_time) { void thk_LedStripController::rainbow_effect(unsigned long wait_time) {
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256)
{ {
for(uint16_t i=0; i<ptrStrip->numPixels(); i++) for(uint16_t i=0; i<ptrStrip->numPixels(); i++)
...@@ -63,7 +63,7 @@ void Ledstrip::rainbow_effect(unsigned long wait_time) { ...@@ -63,7 +63,7 @@ void Ledstrip::rainbow_effect(unsigned long wait_time) {
} }
} }
void Ledstrip::running_light(unsigned long wait_time, uint8_t length, uint32_t color, bool direction) { void thk_LedStripController::running_light(unsigned long wait_time, uint8_t length, uint32_t color, bool direction) {
if (direction){ if (direction){
for(uint16_t i = 0; i <= ptrStrip->numPixels(); i++) { // For each pixel... for(uint16_t i = 0; i <= ptrStrip->numPixels(); i++) { // For each pixel...
......
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
#endif #endif
class Ledstrip { class thk_LedStripController {
public: public:
Ledstrip(const uint16_t MAX_LED_NUMBER, const uint16_t DATA_PIN, uint8_t brightness = 64); thk_LedStripController(const uint16_t MAX_LED_NUMBER, const uint16_t DATA_PIN, uint8_t brightness = 64);
void init(); void init();
void clear(); void clear();
static uint32_t Color(uint8_t red, uint8_t green, uint8_t blue) { return Adafruit_NeoPixel::Color(red, green, blue);}; static uint32_t Color(uint8_t red, uint8_t green, uint8_t blue) { return Adafruit_NeoPixel::Color(red, green, blue);};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment