Mapping fuer Boxen aktualisiert

This commit is contained in:
starcalc 2018-01-03 01:07:32 +01:00
parent 790ec5b867
commit ff6cc12e7f
3 changed files with 159 additions and 18 deletions

View File

@ -11,6 +11,8 @@ NeoPatterns::NeoPatterns(uint16_t pixels, uint8_t pin, uint8_t type, void (*call
pixelR_buffer = ( uint8_t* ) calloc( pixels, sizeof( uint8_t ) );
pixelG_buffer = ( uint8_t* ) calloc( pixels, sizeof( uint8_t ) );
pixelB_buffer = ( uint8_t* ) calloc( pixels, sizeof( uint8_t ) );
setupboxs();
}
void NeoPatterns::Update() {
@ -506,12 +508,122 @@ void NeoPatterns::ColorSet(uint32_t color)
}
void NeoPatterns::colorBox(uint8_t boxid, uint32_t c){ //color a box
for (int i=boxid*3;i<(boxid+1)*3;i++) {
setPixelColor(i, c);
// for (int i=boxid*3;i<(boxid+1)*3;i++) {
// setPixelColor(i, c);
// }
Serial.println("Coloring Box");
setPixelColor(boxs[boxid].left, c);
setPixelColor(boxs[boxid].middle, c);
setPixelColor(boxs[boxid].right, c);
show();
}
void NeoPatterns::setupboxs() {
boxs[1].left = 55;
boxs[1].middle = 56;
boxs[1].right = 57;
boxs[2].left = 52;
boxs[2].middle = 53;
boxs[2].right = 54;
boxs[3].left = 49;
boxs[3].middle = 50;
boxs[3].right = 51;
boxs[4].left = 46;
boxs[4].middle = 47;
boxs[4].right = 48;
boxs[5].left = 43;
boxs[5].middle = 44;
boxs[5].right = 45;
boxs[6].left = 40;
boxs[6].middle = 41;
boxs[6].right = 42;
boxs[7].left = 33;
boxs[7].middle = 38;
boxs[7].right = 38;
boxs[8].left = 32;
boxs[8].middle = 37;
boxs[8].right = 37;
boxs[9].left = 31;
boxs[9].middle = 36;
boxs[9].right = 36;
boxs[10].left = 30;
boxs[10].middle = 35;
boxs[10].right = 35;
boxs[11].left = 29;
boxs[11].middle = 28;
boxs[11].right = 27;
boxs[12].left = 26;
boxs[12].middle = 25;
boxs[12].right = 24;
boxs[13].left = 23;
boxs[13].middle = 22;
boxs[13].right = 21;
boxs[14].left = 20;
boxs[14].middle = 19;
boxs[14].right = 18;
boxs[15].left = 17;
boxs[15].middle = 16;
boxs[15].right = 15;
boxs[16].left = 14;
boxs[16].middle = 13;
boxs[16].right = 12;
boxs[17].left = 11;
boxs[17].middle = 10;
boxs[17].right = 9;
boxs[18].left = 8;
boxs[18].middle = 7;
boxs[18].right = 6;
boxs[19].left = 5;
boxs[19].middle = 4;
boxs[19].right = 3;
boxs[20].left = 2;
boxs[20].middle = 1;
boxs[20].right = 0;
boxs[21].left = 69;
boxs[21].middle = 68;
boxs[21].right = 67;
boxs[22].left = 66;
boxs[22].middle = 65;
boxs[22].right = 64;
boxs[23].left = 63;
boxs[23].middle = 62;
boxs[23].right = 61;
boxs[24].left = 60;
boxs[24].middle = 59;
boxs[24].right = 58;
// Die unterste Zeile ohne Konsole
boxs[0].left = 34;
boxs[0].middle = 39;
boxs[0].right = 39;
}
void NeoPatterns::ColorSetParameters(String parameters)
{
None();

View File

@ -39,6 +39,17 @@ class NeoPatterns : public Adafruit_NeoPixel
void SetColor2(uint32_t color);
//Utilities
void ColorSet(uint32_t color);
struct box
{
int left;
int middle;
int right;
};
struct box boxs[25];
void setupboxs();
void colorBox(uint8_t boxid, uint32_t c);
void ColorSetParameters(String parameters);
uint8_t Red(uint32_t color);

View File

@ -5,8 +5,10 @@
#include "NeoPatterns.h"
#define PIN D7
#define BIGPIXELS 20
#define NUMPIXELS (BIGPIXELS * 3) // 3 LEDs form one pixel
// #define BIGPIXELS 20
#define NUMPIXELS 70 // 3 LEDs form one pixel
#define NUMBOXS 24
// #define NUMPIXELS (BIGPIXELS * 3) // 3 LEDs form one pixel
// #define NUMPIXELS 60
NeoPatterns strip = NeoPatterns(NUMPIXELS, PIN, NEO_BRG + NEO_KHZ400, &StripComplete);
@ -16,7 +18,7 @@ HomieNode homieNode("pixel", "commands");
#define TIMEOUT 500
#define FW_NAME "esp-videoswitcher"
#define FW_VERSION "1.0.1"
#define FW_VERSION "1.0.2"
SoftwareSerial swSer(D2, D1);
int currentnumber = 0;
@ -25,6 +27,23 @@ int commandbytes[4];
String output = "";
String output2 = "";
/*
* 25 Boxen insgesamt
* Box 0, 1, 2
* 0-29 je 3
*
* 40-
* PS1 = 13: 21, 22, 23
* SW Pixel
* 1 55, 56, 57
* 2 52, 53, 54
* 3 49, 50, 51
* 4 46, 47, 48
*
*/
HomieNode switchNode("switch", "switch");
void StripComplete(){
@ -47,15 +66,12 @@ bool onSetColor(const HomieRange& range, const String& value) {
}
bool onSetBox(const HomieRange& range, const String& value) {
if (range.index < 0 || range.index > BIGPIXELS) {
if (range.index < 0 || range.index > (NUMBOXS)) {
return false;
}
strip.None();
strip.setPixelColor(range.index*3, value.toInt());
strip.setPixelColor(range.index*3+1, value.toInt());
strip.setPixelColor(range.index*3+2, value.toInt());
strip.show();
strip.colorBox(range.index, value.toInt());
homieNode.setProperty("box_" + String(range.index)).send(value);
return true;
}
@ -262,7 +278,6 @@ void loopHandler() {
strip.Update();
}
void setup() {
Serial.begin(115200);
swSer.begin(9600);
@ -276,14 +291,14 @@ void setup() {
switchNode.advertise("switch").settable(switchHandler);
homieNode.advertiseRange("pixel", 0, NUMPIXELS - 1).settable(onSetPixel);
homieNode.advertiseRange("box", 0, BIGPIXELS - 1).settable(onSetBox);
homieNode.advertiseRange("box", 0, NUMBOXS - 1).settable(onSetBox);
homieNode.advertiseRange("color", 0, 1).settable(onSetColor);
homieNode.advertise("brightness").settable(onSetBrightness);
homieNode.advertise("effect").settable(onSetEffect);
homieNode.advertise("clear").settable(onSetClear);
homieNode.advertise("length").settable(onSetLength);
homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1)*7).settable(onSetPixels);
homieNode.advertiseRange("boxs", 0, (BIGPIXELS - 1)*7).settable(onSetBoxs);
// homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1)*7).settable(onSetPixels);
// homieNode.advertiseRange("boxs", 0, (BIGPIXELS - 1)*7).settable(onSetBoxs);
Homie.setup();
@ -297,15 +312,18 @@ void setup() {
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId);
ArduinoOTA.onStart([]() {
Serial.println("\nArduinoOTA.onStart()");
strip.clear();
strip.setBrightness(64);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nArduinoOTA.onEnd()");
strip.clear();
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
strip.setPixelColor(progress / (total / NUMPIXELS), strip.Color(100, 0, 0));
strip.show();
Serial.println("\nArduinoOTA.onProgress()");
// strip.setPixelColor(progress / (total / NUMPIXELS), strip.Color(100, 0, 0));
// strip.show();
});
ArduinoOTA.begin();