bugfix led index
This commit is contained in:
parent
2e2d165c62
commit
7108a1dc03
@ -8,14 +8,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// uncomment next line if you want to use NEOPIXEL (3 pins) instead of APA102 (4 pins)
|
// set to true if you want to use NEOPIXEL (3 pins) instead of APA102 (4 pins)
|
||||||
//#define NEOPIXEL
|
#define NEOPIXEL false
|
||||||
// uncomment next line for image test modus, this will change the segments every 1/2 second
|
// set to true for image test modus, this will change the segments every 1/2 second
|
||||||
//#define TEST_STRIPES
|
#define TEST_STRIPES false
|
||||||
|
|
||||||
#include "images.h"
|
#include "images.h"
|
||||||
|
|
||||||
#ifdef NEOPIXEL
|
#if NEOPIXEL
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
#else
|
#else
|
||||||
#include <FastGPIO.h>
|
#include <FastGPIO.h>
|
||||||
@ -31,12 +31,12 @@
|
|||||||
#define LED_COUNT 26 // how many LEDs on one stripe
|
#define LED_COUNT 26 // how many LEDs on one stripe
|
||||||
#define LED_STRIPES 2 // how many LEDs stripes on wheel
|
#define LED_STRIPES 2 // how many LEDs stripes on wheel
|
||||||
|
|
||||||
int strip_matrix_offset[LED_STRIPES] = {0, 0}; // given offset in segments for stripe
|
int strip_matrix_offset[4] = {0, 0, NUM_SEGMENTS / 2, NUM_SEGMENTS / 2}; // given offset in segments for stripe
|
||||||
bool strip_matrix_invert[LED_STRIPES] = {false, true}; // set LEDs in revert order for stripe
|
bool strip_matrix_invert[4] = {false, true, false, true}; // set LEDs in revert order for stripe
|
||||||
// \CONFIGURE
|
// \CONFIGURE
|
||||||
|
|
||||||
// LED stripes
|
// LED stripes
|
||||||
#ifdef NEOPIXEL
|
#if NEOPIXEL
|
||||||
#define LED_PIN 6 // data pin for neopixel LED stripe
|
#define LED_PIN 6 // data pin for neopixel LED stripe
|
||||||
#define BRIGHTNESS 10 // brightness for LED strip [0-255]
|
#define BRIGHTNESS 10 // brightness for LED strip [0-255]
|
||||||
Adafruit_NeoPixel ledStrip(LED_COUNT *LED_STRIPES, LED_PIN, NEO_GRB + NEO_KHZ800);
|
Adafruit_NeoPixel ledStrip(LED_COUNT *LED_STRIPES, LED_PIN, NEO_GRB + NEO_KHZ800);
|
||||||
@ -44,7 +44,7 @@ Adafruit_NeoPixel ledStrip(LED_COUNT *LED_STRIPES, LED_PIN, NEO_GRB + NEO_KHZ800
|
|||||||
#define LED_DATA_PIN 3 // data pin for LED strip
|
#define LED_DATA_PIN 3 // data pin for LED strip
|
||||||
#define LED_CLOCK_PIN 2 // clock pin for LED strip
|
#define LED_CLOCK_PIN 2 // clock pin for LED strip
|
||||||
APA102<LED_DATA_PIN, LED_CLOCK_PIN> ledStrip;
|
APA102<LED_DATA_PIN, LED_CLOCK_PIN> ledStrip;
|
||||||
#define BRIGHTNESS 1 // brightness for LED strip [0-31]
|
#define BRIGHTNESS 10 // brightness for LED strip [0-31]
|
||||||
rgb_color color_buffer[LED_COUNT * LED_STRIPES]; // color buffer to write to LED stripe
|
rgb_color color_buffer[LED_COUNT * LED_STRIPES]; // color buffer to write to LED stripe
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -63,12 +63,12 @@ void setup()
|
|||||||
pinMode(LED_BUILTIN, OUTPUT); // set build-in LED as output
|
pinMode(LED_BUILTIN, OUTPUT); // set build-in LED as output
|
||||||
current_palette = (uint8_t *)pgm_read_word(&images[current_image_index].palette); // init palette for current image
|
current_palette = (uint8_t *)pgm_read_word(&images[current_image_index].palette); // init palette for current image
|
||||||
current_pixels = (uint8_t *)pgm_read_word(&images[current_image_index].pixels); // init pixels for current image
|
current_pixels = (uint8_t *)pgm_read_word(&images[current_image_index].pixels); // init pixels for current image
|
||||||
#ifdef NEOPIXEL
|
#if NEOPIXEL
|
||||||
ledStrip.begin();
|
ledStrip.begin();
|
||||||
ledStrip.show();
|
ledStrip.show();
|
||||||
ledStrip.setBrightness(BRIGHTNESS);
|
ledStrip.setBrightness(BRIGHTNESS);
|
||||||
#else
|
#else
|
||||||
for (int i = 0; i < LED_COUNT * 4; i++) // loop over all LEDs
|
for (int i = 0; i < LED_COUNT * LED_STRIPES; i++) // loop over all LEDs
|
||||||
{
|
{
|
||||||
color_buffer[i] = rgb_color(0, 0, 0); // set to black
|
color_buffer[i] = rgb_color(0, 0, 0); // set to black
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ void loop()
|
|||||||
|
|
||||||
float current_diff = micros() - start; // get time passed in current loop
|
float current_diff = micros() - start; // get time passed in current loop
|
||||||
|
|
||||||
#ifdef TEST_STRIPES // testing stripes
|
#if TEST_STRIPES // testing stripes
|
||||||
int segment = (micros() / 500000) % NUM_SEGMENTS; // calculate current segment as half seconds passed since runtime
|
int segment = (micros() / 500000) % NUM_SEGMENTS; // calculate current segment as half seconds passed since runtime
|
||||||
if (segment == current_segment) // do nothing if still in old segment
|
if (segment == current_segment) // do nothing if still in old segment
|
||||||
{
|
{
|
||||||
@ -120,8 +120,8 @@ void loop()
|
|||||||
for (int i = 0; i < LED_COUNT; i++) // loop over all LEDs of current strip
|
for (int i = 0; i < LED_COUNT; i++) // loop over all LEDs of current strip
|
||||||
{
|
{
|
||||||
pixel_color_index = pgm_read_byte(current_pixel++) * 3; // read color palette index for current pixel
|
pixel_color_index = pgm_read_byte(current_pixel++) * 3; // read color palette index for current pixel
|
||||||
uint8_t pixel_index = strip * LED_COUNT + (strip_matrix_invert[strip] ? (LED_COUNT - i) : i); // calculate index of LED with offset and inversion
|
uint8_t pixel_index = strip * LED_COUNT + (strip_matrix_invert[strip] ? (LED_COUNT - i - 1) : i); // calculate index of LED with offset and inversion
|
||||||
#ifdef NEOPIXEL
|
#if NEOPIXEL
|
||||||
// set pixel of NEOPIXEL
|
// set pixel of NEOPIXEL
|
||||||
ledStrip.setPixelColor(pixel_index, pgm_read_byte(¤t_palette[pixel_color_index]),
|
ledStrip.setPixelColor(pixel_index, pgm_read_byte(¤t_palette[pixel_color_index]),
|
||||||
pgm_read_byte(¤t_palette[pixel_color_index + 1]),
|
pgm_read_byte(¤t_palette[pixel_color_index + 1]),
|
||||||
@ -135,7 +135,7 @@ void loop()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef NEOPIXEL
|
#if NEOPIXEL
|
||||||
ledStrip.show(); // update pixel
|
ledStrip.show(); // update pixel
|
||||||
#else
|
#else
|
||||||
ledStrip.write(color_buffer, LED_COUNT * LED_STRIPES, BRIGHTNESS); // write buffer to stripes
|
ledStrip.write(color_buffer, LED_COUNT * LED_STRIPES, BRIGHTNESS); // write buffer to stripes
|
||||||
|
Loading…
Reference in New Issue
Block a user