diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index 9216a1f0..4279e3f4 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -256,6 +256,26 @@ void saveConfigCallback () { #include "custom_ws2812fx_animations.h" // Add animations in this file #endif +#ifdef OFFSET +void OffsetShow(void) { + static uint8_t tmpPixels[NUMLEDS * 4]; // allocate space for a copy of the ADafruit pixel data + uint8_t bytesPerPixel = strip->getNumBytes() / strip->getLength(); // 3=RGB, 4=RGBW + + // copy the Adafruit pixel array + memcpy(tmpPixels, strip->getPixels(), strip->getNumBytes()); + + // offset the data in the Adafruit pixel array + memcpy(strip->getPixels() + OFFSET * bytesPerPixel, tmpPixels, (NUMLEDS - OFFSET) * bytesPerPixel); + memcpy(strip->getPixels(), tmpPixels + (NUMLEDS - OFFSET) * bytesPerPixel, OFFSET * bytesPerPixel); + + // run the standard Adafruit show() function + strip->Adafruit_NeoPixel::show(); + + // copy the original pixel data back to the Adafruit pixel array + memcpy(strip->getPixels(), tmpPixels, strip->getNumBytes()); +} +#endif + // function to Initialize the strip void initStrip(uint16_t stripSize = WS2812FXStripSettings.stripSize, neoPixelType RGBOrder = WS2812FXStripSettings.RGBOrder, uint8_t pin = WS2812FXStripSettings.pin){ if (strip) { @@ -283,6 +303,10 @@ void initStrip(uint16_t stripSize = WS2812FXStripSettings.stripSize, neoPixelTyp // on a live circuit...if you must, connect GND first. strip->init(); + #ifdef OFFSET + strip->setCustomShow(OffsetShow); + #endif + #if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART1) or defined(USE_WS2812FX_UART2) initDMA(stripSize); strip->setCustomShow(DMA_Show); diff --git a/Arduino/McLighting/definitions.h b/Arduino/McLighting/definitions.h index 835cbeea..80cfa369 100644 --- a/Arduino/McLighting/definitions.h +++ b/Arduino/McLighting/definitions.h @@ -5,6 +5,8 @@ // Neopixel #define LED_PIN 14 // LED_PIN (14 / D5) where neopixel / WS2811 strip is attached #define NUMLEDS 24 // Number of leds in the strip +// +//#define OFFSET // If defined, first led of starting effect like dual scan,scan etc, is traslated of OFFSET number of leds. Not use this in conjuction of USE_WS2812FX_DMA,USE_WS2812FX_UART1 or USE_WS2812FX_UART2 //#define LED_TYPE_WS2811 // Uncomment if LED type uses 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) #define BUILTIN_LED 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192 #define BUTTON 4 // Input pin (4 / D2) for switching the LED strip on / off, connect this PIN to ground to trigger button. diff --git a/README.md b/README.md index dcb0e439..3b5666d0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # McLighting v2 - The ESP8266 based multi-client lighting gadget +This version, add ability to translate starting led of effect by OFFSET number of leds, respect of elettric wire of led strip. +Thanks to @moose4lord + [![Gitter](https://badges.gitter.im/mclighting/Lobby.svg)](https://gitter.im/mclighting/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Build Status](https://travis-ci.com/toblum/McLighting.svg?branch=master)](https://travis-ci.com/toblum/McLighting) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![version](https://img.shields.io/badge/version-v2.2.4-blue.svg)](https://github.com/toblum/McLighting/blob/master/Arduino/McLighting/version.h) McLighting (the multi-client lighting gadget) is a very cheap internet-controllable lighting solution based on the famous ESP8266 microcontroller and WS2811/2812 led strips. It features among other things a web-interface, a REST-API and a websocket connector.