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
|
||||
// limitations under the License.
|
||||
|
||||
// uncomment next line if you want to use NEOPIXEL (3 pins) instead of APA102 (4 pins)
|
||||
//#define NEOPIXEL
|
||||
// uncomment next line for image test modus, this will change the segments every 1/2 second
|
||||
//#define TEST_STRIPES
|
||||
// set to true if you want to use NEOPIXEL (3 pins) instead of APA102 (4 pins)
|
||||
#define NEOPIXEL false
|
||||
// set to true for image test modus, this will change the segments every 1/2 second
|
||||
#define TEST_STRIPES false
|
||||
|
||||
#include "images.h"
|
||||
|
||||
#ifdef NEOPIXEL
|
||||
#if NEOPIXEL
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#else
|
||||
#include <FastGPIO.h>
|
||||
@ -31,12 +31,12 @@
|
||||
#define LED_COUNT 26 // how many LEDs on one stripe
|
||||
#define LED_STRIPES 2 // how many LEDs stripes on wheel
|
||||
|
||||
int strip_matrix_offset[LED_STRIPES] = {0, 0}; // given offset in segments for stripe
|
||||
bool strip_matrix_invert[LED_STRIPES] = {false, true}; // set LEDs in revert order 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[4] = {false, true, false, true}; // set LEDs in revert order for stripe
|
||||
// \CONFIGURE
|
||||
|
||||
// LED stripes
|
||||
#ifdef NEOPIXEL
|
||||
#if NEOPIXEL
|
||||
#define LED_PIN 6 // data pin for neopixel LED stripe
|
||||
#define BRIGHTNESS 10 // brightness for LED strip [0-255]
|
||||
Adafruit_NeoPixel ledStrip(LED_COUNT *LED_STRIPES, LED_PIN, NEO_GRB + NEO_KHZ800);
|
||||
@ -44,8 +44,8 @@ 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_CLOCK_PIN 2 // clock pin for LED strip
|
||||
APA102<LED_DATA_PIN, LED_CLOCK_PIN> ledStrip;
|
||||
#define BRIGHTNESS 1 // brightness for LED strip [0-31]
|
||||
rgb_color color_buffer[LED_COUNT * LED_STRIPES]; // color buffer to write to LED stripe
|
||||
#define BRIGHTNESS 10 // brightness for LED strip [0-31]
|
||||
rgb_color color_buffer[LED_COUNT * LED_STRIPES]; // color buffer to write to LED stripe
|
||||
#endif
|
||||
|
||||
float passed = 0;
|
||||
@ -63,12 +63,12 @@ void setup()
|
||||
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_pixels = (uint8_t *)pgm_read_word(&images[current_image_index].pixels); // init pixels for current image
|
||||
#ifdef NEOPIXEL
|
||||
#if NEOPIXEL
|
||||
ledStrip.begin();
|
||||
ledStrip.show();
|
||||
ledStrip.setBrightness(BRIGHTNESS);
|
||||
#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
|
||||
}
|
||||
@ -100,7 +100,7 @@ void 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
|
||||
if (segment == current_segment) // do nothing if still in old segment
|
||||
{
|
||||
@ -119,9 +119,9 @@ void loop()
|
||||
uint8_t *current_pixel = (uint8_t *)¤t_pixels[((current_segment + strip_matrix_offset[strip]) % NUM_SEGMENTS) * LED_COUNT];
|
||||
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
|
||||
uint8_t pixel_index = strip * LED_COUNT + (strip_matrix_invert[strip] ? (LED_COUNT - i) : i); // calculate index of LED with offset and inversion
|
||||
#ifdef NEOPIXEL
|
||||
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 - 1) : i); // calculate index of LED with offset and inversion
|
||||
#if NEOPIXEL
|
||||
// set pixel of NEOPIXEL
|
||||
ledStrip.setPixelColor(pixel_index, pgm_read_byte(¤t_palette[pixel_color_index]),
|
||||
pgm_read_byte(¤t_palette[pixel_color_index + 1]),
|
||||
@ -135,7 +135,7 @@ void loop()
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef NEOPIXEL
|
||||
#if NEOPIXEL
|
||||
ledStrip.show(); // update pixel
|
||||
#else
|
||||
ledStrip.write(color_buffer, LED_COUNT * LED_STRIPES, BRIGHTNESS); // write buffer to stripes
|
||||
|
Loading…
Reference in New Issue
Block a user