Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FastSPI_LED2.h237
-rw-r--r--clockless.h116
-rw-r--r--controller.h9
-rw-r--r--examples/Fast2Dev/Fast2Dev.ino114
-rw-r--r--fastspi.h1
5 files changed, 167 insertions, 310 deletions
diff --git a/FastSPI_LED2.h b/FastSPI_LED2.h
index 9b49dbca..3f3fe532 100644
--- a/FastSPI_LED2.h
+++ b/FastSPI_LED2.h
@@ -7,241 +7,6 @@
#include "clockless.h"
#include "lib8tion.h"
#include "hsv2rgb.h"
-
-
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//
-// LPD8806 controller class - takes data/clock/select pin values (N.B. should take an SPI definition?)
-//
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-template<uint8_t DATA_PIN, uint8_t CLOCK_PIN, uint8_t SPI_SPEED> class LPD8806_ADJUST {
- typedef SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
-public:
- // LPD8806 spec wants the high bit of every rgb data byte sent out to be set.
- __attribute__((always_inline)) inline static uint8_t adjust(register uint8_t data) { return (data>>1) | 0x80; }
- __attribute__((always_inline)) inline static uint8_t adjust(register uint8_t data, register uint8_t scale) { return (scale8(data, scale)>>1) | 0x80; }
- __attribute__((always_inline)) inline static void postBlock(int len) {
- SPI::writeBytesValueRaw(0, ((len+63)>>6));
- }
-
-};
-
-template <uint8_t DATA_PIN, uint8_t CLOCK_PIN, uint8_t SELECT_PIN, EOrder RGB_ORDER = RGB, uint8_t SPI_SPEED = 2 >
-class LPD8806Controller : public CLEDController {
- typedef SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
- SPI mSPI;
- int mClearedLeds;
-
- void checkClear(int nLeds) {
- if(nLeds > mClearedLeds) {
- clearLine(nLeds);
- mClearedLeds = nLeds;
- }
- }
-
- void clearLine(int nLeds) {
- int n = ((nLeds + 63) >> 6);
- mSPI.writeBytesValue(0, n);
- }
-public:
- LPD8806Controller() {}
- virtual void init() {
- if(SELECT_PIN != NO_PIN) {
- mSPI.setSelect(new OutputPin(SELECT_PIN));
- } else {
- // mSPI.setSelect(NULL);
- }
- mSPI.init();
- mClearedLeds = 0;
- }
-
- virtual void clearLeds(int nLeds) {
- checkClear(nLeds);
- mSPI.writeBytesValue(0x80, nLeds * 3);
- }
-
- virtual void showRGB(register struct CRGB *rgbdata, register int nLeds) {
- showRGB(rgbdata, nLeds, 255);
- }
-
- virtual void showRGB(struct CRGB *data, int nLeds, uint8_t scale) {
- mSPI.template writeBytes3<LPD8806_ADJUST<DATA_PIN, CLOCK_PIN, SPI_SPEED>, RGB_ORDER>((byte*)data, nLeds * 3, scale);
- }
-
-#ifdef SUPPORT_ARGB
- virtual void showARGB(struct CARGB *data, int nLeds) {
- checkClear(nLeds);
- mSPI.template writeBytes3<1, LPD8806_ADJUST<DATA_PIN, CLOCK_PIN, SPI_SPEED>, RGB_ORDER>((byte*)data, nLeds * 4, 255);
- }
-#endif
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//
-// WS2801 definition - takes data/clock/select pin values (N.B. should take an SPI definition?)
-//
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-template <uint8_t DATA_PIN, uint8_t CLOCK_PIN, uint8_t SELECT_PIN, EOrder RGB_ORDER = RGB, uint8_t SPI_SPEED = 3>
-class WS2801Controller : public CLEDController {
- typedef SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
- SPI mSPI;
- CMinWait<24> mWaitDelay;
-public:
- WS2801Controller() {}
-
- virtual void init() {
- if(SELECT_PIN != NO_PIN) {
- mSPI.setSelect(new OutputPin(SELECT_PIN));
- } else {
- mSPI.setSelect(NULL);
- }
- mSPI.init();
- // 0 out as much as we can on the line
- mSPI.writeBytesValue(0, 1000);
- mWaitDelay.mark();
- }
-
- virtual void clearLeds(int nLeds) {
- mWaitDelay.wait();
- mSPI.writeBytesValue(0, nLeds*3);
- mWaitDelay.mark();
- }
-
- virtual void showRGB(register struct CRGB *rgbdata, register int nLeds) {
- showRGB(rgbdata, nLeds, 255);
- }
-
- virtual void showRGB(struct CRGB *data, int nLeds, uint8_t scale) {
- mWaitDelay.wait();
- mSPI.template writeBytes3<0, RGB_ORDER>((byte*)data, nLeds * 3, scale);
- mWaitDelay.mark();
- }
-
-#ifdef SUPPORT_ARGB
- virtual void showARGB(struct CRGB *data, int nLeds) {
- mWaitDelay.wait();
- mSPI.template writeBytes3<1, RGB_ORDER>((byte*)data, nLeds * 4, 255);
- mWaitDelay.mark();
- }
-#endif
-};
-
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//
-// SM16716 definition - takes data/clock/select pin values (N.B. should take an SPI definition?)
-//
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
-template <uint8_t DATA_PIN, uint8_t CLOCK_PIN, uint8_t SELECT_PIN, EOrder RGB_ORDER = RGB, uint8_t SPI_SPEED = 0>
-class SM16716Controller : public CLEDController {
-#if defined(__MK20DX128__) // for Teensy 3.0
- // Have to force software SPI for the teensy 3.0 right now because it doesn't deal well
- // with flipping in and out of hardware SPI
- typedef SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
-#else
- typedef SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
-#endif
- SPI mSPI;
- OutputPin selectPin;
-
- void writeHeader() {
- // Write out 50 zeros to the spi line (6 blocks of 8 followed by two single bit writes)
- mSPI.writeBytesValue(0, 6);
- mSPI.template writeBit<0>(0);
- mSPI.template writeBit<0>(0);
- }
-
-public:
- SM16716Controller() : selectPin(SELECT_PIN) {}
-
- virtual void init() {
- mSPI.setSelect(&selectPin);
- mSPI.init();
- }
-
- virtual void clearLeds(int nLeds) {
- mSPI.select();
- writeHeader();
- while(nLeds--) {
- mSPI.template writeBit<0>(1);
- mSPI.writeByte(0);
- mSPI.writeByte(0);
- mSPI.writeByte(0);
- }
- mSPI.waitFully();
- mSPI.release();
- }
-
- virtual void showRGB(register struct CRGB *rgbdata, register int nLeds) {
- writeHeader();
- showRGB(rgbdata, nLeds, 255);
- }
-
- virtual void showRGB(struct CRGB *data, int nLeds, uint8_t scale) {
- // Make sure the FLAG_START_BIT flag is set to ensure that an extra 1 bit is sent at the start
- // of each triplet of bytes for rgb data
- writeHeader();
- mSPI.template writeBytes3<FLAG_START_BIT, RGB_ORDER>((byte*)data, nLeds * 3, scale);
- }
-
-#ifdef SUPPORT_ARGB
- virtual void showARGB(struct CARGB *data, int nLeds) {
- mSPI.writeBytesValue(0, 6);
- mSPI.template writeBit<0>(0);
- mSPI.template writeBit<0>(0);
-
- // Make sure the FLAG_START_BIT flag is set to ensure that an extra 1 bit is sent at the start
- // of each triplet of bytes for rgb data
- mSPI.template writeBytes3<1 | FLAG_START_BIT, RGB_ORDER>((byte*)data, nLeds * 4, 255);
- }
-#endif
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//
-// Clockless template instantiations
-//
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-// 500ns, 1500ns, 500ns
-template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
-class UCS1903Controller400Mhz : public ClocklessController<DATA_PIN, NS(500), NS(1500), NS(500), RGB_ORDER> {};
-template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
-class UCS1903Controller400Khz : public ClocklessController<DATA_PIN, NS(500), NS(1500), NS(500), RGB_ORDER> {};
-#if NO_TIME(500, 1500, 500)
-#warning "No enough clock cycles available for the UCS103"
-#endif
-
-// 312.5ns, 312.5ns, 325ns
-template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
-class TM1809Controller800Mhz : public ClocklessController<DATA_PIN, NS(350), NS(350), NS(550), RGB_ORDER> {};
-template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
-class TM1809Controller800Khz : public ClocklessController<DATA_PIN, NS(350), NS(350), NS(550), RGB_ORDER> {};
-#if NO_TIME(350, 350, 550)
-#warning "No enough clock cycles available for the UCS103"
-#endif
-
-// 350n, 350ns, 550ns
-template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
-class WS2811Controller800Mhz : public ClocklessController<DATA_PIN, NS(320), NS(320), NS(550), RGB_ORDER> {};
-template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
-class WS2811Controller800Khz : public ClocklessController<DATA_PIN, NS(320), NS(320), NS(550), RGB_ORDER> {};
-#if NO_TIME(320, 320, 550)
-#warning "No enough clock cycles available for the UCS103"
-#endif
-
-// 750NS, 750NS, 750NS
-template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
-class TM1803Controller400Mhz : public ClocklessController<DATA_PIN, NS(750), NS(750), NS(750), RGB_ORDER> {};
-template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
-class TM1803Controller400Khz : public ClocklessController<DATA_PIN, NS(750), NS(750), NS(750), RGB_ORDER> {};
-#if NO_TIME(750, 750, 750)
-#warning "No enough clock cycles available for the UCS103"
-#endif
+#include "chipsets.h"
#endif \ No newline at end of file
diff --git a/clockless.h b/clockless.h
index b882c84a..81f0811f 100644
--- a/clockless.h
+++ b/clockless.h
@@ -84,18 +84,50 @@ public:
#endif
virtual void clearLeds(int nLeds) {
- // can't do anything quickly/easily here - oops
+ showColor(CRGB(0, 0, 0), nLeds, 0);
}
- virtual void showRGB(register struct CRGB *rgbdata, register int nLeds) {
- showRGB(rgbdata, nLeds, 255);
+ // set all the leds on the controller to a given color
+ virtual void showColor(const struct CRGB & data, int nLeds, uint8_t scale = 255) {
+ mWait.wait();
+ cli();
+
+ showRGBInternal<0, false>(nLeds, scale, (const byte*)&data);
+
+ // Adjust the timer
+ long microsTaken = CLKS_TO_MICROS(nLeds * 8 * (T1 + T2 + T3));
+#if defined(__MK20DX128__)
+ systick_millis_count += (microsTaken / 1000);
+#else
+ timer0_millis += (microsTaken / 1000);
+#endif
+ sei();
+ mWait.mark();
}
-
- virtual void showRGB(struct CRGB *rgbdata, int nLeds, int scale) {
+
+ virtual void show(const struct CRGB *rgbdata, int nLeds, uint8_t scale = 255) {
+ mWait.wait();
+ cli();
+
+ showRGBInternal<0, true>(nLeds, scale, (const byte*)rgbdata);
+
+ // Adjust the timer
+ long microsTaken = CLKS_TO_MICROS(nLeds * 8 * (T1 + T2 + T3));
+#if defined(__MK20DX128__)
+ systick_millis_count += (microsTaken / 1000);
+#else
+ timer0_millis += (microsTaken / 1000);
+#endif
+ sei();
+ mWait.mark();
+ }
+
+#ifdef SUPPORT_ARGB
+ virtual void show(const struct CARGB *rgbdata, int nLeds, uint8_t scale = 255) {
mWait.wait();
cli();
- showRGBInternal(nLeds, scale, rgbdata);
+ showRGBInternal<1, true>(nLeds, scale, (const byte*)rgbdata);
// Adjust the timer
long microsTaken = CLKS_TO_MICROS(nLeds * 8 * (T1 + T2 + T3));
@@ -107,21 +139,28 @@ public:
sei();
mWait.mark();
}
+#endif
// This method is made static to force making register Y available to use for data on AVR - if the method is non-static, then
// gcc will use register Y for the this pointer.
- static void showRGBInternal(register int nLeds, register uint8_t scale, register struct CRGB *rgbdata) __attribute__((noinline)) {
+ template<int SKIP, bool ADVANCE> static void showRGBInternal(register int nLeds, register uint8_t scale, register const byte *rgbdata) {
register byte *data = (byte*)rgbdata;
register data_t mask = FastPin<DATA_PIN>::mask();
register data_ptr_t port = FastPin<DATA_PIN>::port();
- nLeds *= (3);
+ nLeds *= (3 + SKIP);
register uint8_t *end = data + nLeds;
register data_t hi = *port | mask;
register data_t lo = *port & ~mask;
*port = lo;
#if defined(__MK20DX128__)
- register uint32_t b = scale8(data[RGB_BYTE0(RGB_ORDER)], scale);
+ register uint32_t b;
+ if(ADVANCE) {
+ b = data[SKIP + RGB_BYTE0(RGB_ORDER)];
+ } else {
+ b = rgbdata[SKIP + RGB_BYTE0(RGB_ORDER)];
+ }
+ b = scale8(b, scale);
while(data < end) {
// TODO: hand rig asm version of this method. The timings are based on adjusting/studying GCC compiler ouptut. This
// will bite me in the ass at some point, I know it.
@@ -143,7 +182,14 @@ public:
if(b & 0x80) { FastPin<DATA_PIN>::fastset(port, hi); } else { FastPin<DATA_PIN>::fastset(port, lo); }
delaycycles<T2 - 2>(); // 4 cycles, 2 store, store/skip
FastPin<DATA_PIN>::fastset(port, lo);
- b = scale8(data[RGB_BYTE1(RGB_ORDER)], scale);
+
+ if(ADVANCE) {
+ b = data[SKIP + RGB_BYTE1(RGB_ORDER)];
+ } else {
+ b = rgbdata[SKIP + RGB_BYTE1(RGB_ORDER)];
+ }
+ b = scale8(b, scale);
+
delaycycles<T3 - 5>(); // 1 store, 2 load, 1 mul, 1 shift,
for(register uint32_t i = 7; i > 0; i--) {
@@ -164,8 +210,15 @@ public:
if(b & 0x80) { FastPin<DATA_PIN>::fastset(port, hi); } else { FastPin<DATA_PIN>::fastset(port, lo); }
delaycycles<T2 - 2>(); // 4 cycles, 2 store, store/skip
FastPin<DATA_PIN>::fastset(port, lo);
- b = scale8(data[RGB_BYTE2(RGB_ORDER)], scale);
- data += 3;
+
+ if(ADVANCE) {
+ b = data[SKIP + RGB_BYTE2(RGB_ORDER)];
+ } else {
+ b = rgbdata[SKIP + RGB_BYTE2(RGB_ORDER)];
+ }
+ b = scale8(b, scale);
+
+ data += 3 + SKIP;
if((RGB_ORDER & 0070) == 0) {
delaycycles<T3 - 6>(); // 1 store, 2 load, 1 mul, 1 shift, 1 adds if BRG or GRB
} else {
@@ -190,7 +243,14 @@ public:
if(b & 0x80) { FastPin<DATA_PIN>::fastset(port, hi); } else { FastPin<DATA_PIN>::fastset(port, lo); }
delaycycles<T2 - 2>(); // 4 cycles, 2 store, store/skip
FastPin<DATA_PIN>::fastset(port, lo);
- b = scale8(data[RGB_BYTE0(RGB_ORDER)], scale);
+
+ if(ADVANCE) {
+ b = data[SKIP + RGB_BYTE0(RGB_ORDER)];
+ } else {
+ b = rgbdata[SKIP + RGB_BYTE0(RGB_ORDER)];
+ }
+ b = scale8(b, scale);
+
delaycycles<T3 - 8>(); // 1 store, 2 load (with increment), 1 mul, 1 shift, 1 cmp, 1 branch backwards, 1 movim
};
#else
@@ -212,7 +272,15 @@ public:
b = next;
}
#else
- register uint8_t b = data[RGB_BYTE0(RGB_ORDER)];
+ register uint8_t b;
+
+ if(ADVANCE) {
+ b = data[SKIP + RGB_BYTE0(RGB_ORDER)];
+ } else {
+ b = rgbdata[SKIP + RGB_BYTE0(RGB_ORDER)];
+ }
+ b = scale8_LEAVING_R1_DIRTY(b, scale);
+
register uint8_t c;
register uint8_t d;
while(data < end) {
@@ -225,7 +293,11 @@ public:
bitSetLast<7, 0>(port, hi, lo, b);
// Leave an extra 4 clocks for the scale
bitSetLast<6, 5>(port, hi, lo, b);
- c = data[RGB_BYTE1(RGB_ORDER)];
+ if(ADVANCE) {
+ c = data[SKIP + RGB_BYTE1(RGB_ORDER)];
+ } else {
+ c = rgbdata[SKIP + RGB_BYTE1(RGB_ORDER)];
+ }
c = scale8_LEAVING_R1_DIRTY(c, scale);
bitSetLast<5, 1>(port, hi, lo, b);
@@ -238,7 +310,11 @@ public:
bitSetLast<7, 0>(port, hi, lo, c);
// Leave an extra 4 clocks for the scale
bitSetLast<6, 5>(port, hi, lo, c);
- d = data[RGB_BYTE2(RGB_ORDER)];
+ if(ADVANCE) {
+ d = data[SKIP + RGB_BYTE2(RGB_ORDER)];
+ } else {
+ d = rgbdata[SKIP + RGB_BYTE2(RGB_ORDER)];
+ }
d = scale8_LEAVING_R1_DIRTY(d, scale);
bitSetLast<5, 1>(port, hi, lo, c);
@@ -249,10 +325,14 @@ public:
delaycycles<1>();
// Leave an extra 2 clocks for the next byte load
bitSetLast<7, 2>(port, hi, lo, d);
- data += 3;
+ data += (SKIP + 3);
// Leave an extra 4 clocks for the scale
bitSetLast<6, 5>(port, hi, lo, d);
- b = data[RGB_BYTE0(RGB_ORDER)];
+ if(ADVANCE) {
+ b = data[SKIP + RGB_BYTE0(RGB_ORDER)];
+ } else {
+ b = rgbdata[SKIP + RGB_BYTE0(RGB_ORDER)];
+ }
b = scale8_LEAVING_R1_DIRTY(b, scale);
bitSetLast<5, 6>(port, hi, lo, d);
}
diff --git a/controller.h b/controller.h
index 7654f8f3..2c703f00 100644
--- a/controller.h
+++ b/controller.h
@@ -32,14 +32,17 @@ public:
// clear out/zero out the given number of leds.
virtual void clearLeds(int nLeds) = 0;
-
+
+ // set all the leds on the controller to a given color
+ virtual void showColor(const struct CRGB & data, int nLeds, uint8_t scale = 255) = 0;
+
// note that the uint8_ts will be in the order that you want them sent out to the device.
// nLeds is the number of RGB leds being written to
- virtual void showRGB(struct CRGB *data, int nLeds) = 0;
+ virtual void show(const struct CRGB *data, int nLeds, uint8_t scale = 255) = 0;
#ifdef SUPPORT_ARGB
// as above, but every 4th uint8_t is assumed to be alpha channel data, and will be skipped
- virtual void showARGB(struct CARGB *data, int nLeds) = 0;
+ virtual void show(const struct CARGB *data, int nLeds, uint8_t scale = 255) = 0;
#endif
// is the controller ready to write data out
diff --git a/examples/Fast2Dev/Fast2Dev.ino b/examples/Fast2Dev/Fast2Dev.ino
index 090568b5..4ffb696d 100644
--- a/examples/Fast2Dev/Fast2Dev.ino
+++ b/examples/Fast2Dev/Fast2Dev.ino
@@ -2,8 +2,7 @@
// #define FORCE_SOFTWARE_SPI 1
#include "FastSPI_LED2.h"
-//
-#define DEBUG
+// #define DEBUG
#ifdef DEBUG
#define DPRINT Serial.print
#define DPRINTLN Serial.println
@@ -23,6 +22,7 @@
// struct CRGB { byte g; byte r; byte b; };
struct CRGB leds[NUM_LEDS];
+struct CHSV hsv[NUM_LEDS];
// gdn clk data pwr
// Note: timing values in the code below are stale/out of date
@@ -30,10 +30,10 @@ struct CRGB leds[NUM_LEDS];
// Hardware SPI - .652ms for an 86 led frame @8Mhz (3.1Mbps?), .913ms @4Mhz 1.434ms @2Mhz
// Hardware SPIr2 - .539ms @8Mhz, .799 @4Mhz, 1.315ms @2Mhz
// With the wait ordering reversed, .520ms at 8Mhz, .779ms @4Mhz, 1.3ms @2Mhz
-LPD8806Controller<11, 13, NO_PIN, RBG, MAX_DATA_RATE> LED;
-LPD8806Controller<11, 13, NO_PIN, RBG, DATA_RATE_MHZ(1)> LEDSlow;
+// LPD8806Controller<11, 13, NO_PIN, RBG, DATA_RATE_MHZ(24)> LED;
+// LPD8806Controller<11, 13, NO_PIN, RBG, DATA_RATE_MHZ(1)> LEDSlow;
-// SM16716Controller<11, 13, 10> LED;
+// SM16716Controller<11, 13, 10, RGB, 4> LED;
//LPD8806Controller<11, 13, 14> LED;
// LPD8806Controller<2, 1, 0> LED; // teensy pins
@@ -65,7 +65,7 @@ LPD8806Controller<11, 13, NO_PIN, RBG, DATA_RATE_MHZ(1)> LEDSlow;
// TM1809Controller800Khz<4, RGB> LED;
// UCS1903Controller400Khz<7> LED;
// WS2811Controller800Khz<12, BRG> LED;
-// WS2811Controller800Khz<23> LED;
+WS2811Controller800Khz<23, GRB> LED;
// TM1803Controller400Khz<5> LED;
//////////////////////////////////////////////////////////////////////////////////////
@@ -75,18 +75,18 @@ LPD8806Controller<11, 13, NO_PIN, RBG, DATA_RATE_MHZ(1)> LEDSlow;
// int ledset = 0;
// void show() {
// switch(ledset) {
-// case 0: LED.showRGB((byte*)leds, NUM_LEDS); break;
-// // case 1: LED2.showRGB((byte*)leds, NUM_LEDS); break;
-// // case 2: LED3.showRGB((byte*)leds, NUM_LEDS); break;
-// // case 3: LED4.showRGB((byte*)leds, NUM_LEDS); break;
-// // case 4: LED5.showRGB((byte*)leds, NUM_LEDS); break;
+// case 0: LED.show((byte*)leds, NUM_LEDS); break;
+// // case 1: LED2.show((byte*)leds, NUM_LEDS); break;
+// // case 2: LED3.show((byte*)leds, NUM_LEDS); break;
+// // case 3: LED4.show((byte*)leds, NUM_LEDS); break;
+// // case 4: LED5.show((byte*)leds, NUM_LEDS); break;
// }
-// // LED.showRGB((byte*)leds, NUM_LEDS);
-// // LED2.showRGB((byte*)leds, NUM_LEDS);
-// // LED3.showRGB((byte*)leds, NUM_LEDS);
-// // LED4.showRGB((byte*)leds, NUM_LEDS);
-// // LED5.showRGB((byte*)leds, NUM_LEDS);
+// // LED.show((byte*)leds, NUM_LEDS);
+// // LED2.show((byte*)leds, NUM_LEDS);
+// // LED3.show((byte*)leds, NUM_LEDS);
+// // LED4.show((byte*)leds, NUM_LEDS);
+// // LED5.show((byte*)leds, NUM_LEDS);
// memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
// }
@@ -103,14 +103,18 @@ void setup() {
Serial.begin(38400);
Serial.println("resetting!");
+#else
+ delay(2000);
#endif
- LEDSlow.init();
- LEDSlow.clearLeds(300);
+ // LEDSlow.init();
+ // LEDSlow.clearLeds(300);
LED.init();
#ifdef DEBUG
+ memset(hsv, 0, NUM_LEDS * sizeof(struct CHSV));
+
unsigned long emptyStart = millis();
for(volatile int i = 0 ; i < 10000; i++) {
volRun(leds, NUM_LEDS);
@@ -118,8 +122,8 @@ void setup() {
unsigned long emptyEnd = millis();
unsigned long start = millis();
for(volatile int i = 0; i < 10000; i++){
- LED.showRGB(leds, NUM_LEDS);
- // LED2.showRGB((byte*)leds, NUM_LEDS);
+ LED.show(leds, NUM_LEDS);
+ // LED2.show((byte*)leds, NUM_LEDS);
}
unsigned long end = millis();
DPRINT("Time for 10000 empty loops: "); DPRINTLN( emptyEnd - emptyStart);
@@ -132,48 +136,52 @@ int count = 0;
long start = millis();
void loop() {
-#if 0
- memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
- LED.showRGB(leds, NUM_LEDS);
- delay(20);
-#else
for(int i = 0; i < 3; i++) {
for(int iLed = 0; iLed < NUM_LEDS; iLed++) {
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
+
switch(i) {
+ // You can access the rgb values by field r, g, b
case 0: leds[iLed].r = 128; break;
- case 1: leds[iLed].g = 128; break;
- case 2: leds[iLed].b = 128; break;
- }
- LED.showRGB(leds, NUM_LEDS);;
- //DPRINTLN("waiting");
+ // or by indexing into the led (r==0, g==1, b==2)
+ case 1: leds[iLed][i] = 128; break;
+
+ // or by setting the rgb values for the pixel all at once
+ case 2: leds[iLed] = CRGB(0, 0, 128); break;
+ }
+
+ // and now, show your led array!
+ LED.show(leds, NUM_LEDS);;
delay(20);
}
- memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
- for(int iLed = NUM_LEDS - 6; iLed < NUM_LEDS; iLed++) {
- switch(i) {
- case 0: leds[iLed].r = 255; break;
- case 1: leds[iLed].g = 255; break;
- case 2: leds[iLed].b = 255; break;
- }
+ LED.show(leds, NUM_LEDS);
+ delay(2000);
+
+ // fade up
+ for(int i = 0; i < 128; i++) {
+ // The showColor method sets all the leds in the strip to the same color
+ LED.showColor(CRGB(i, 0, 0), NUM_LEDS);
+ delay(10);
}
- LED.showRGB(leds, NUM_LEDS);
- delay(2000);
+ // fade down
+ for(int i = 128; i >= 0; i--) {
+ LED.showColor(CRGB(i, 0, 0), NUM_LEDS);
+ delay(10);
+ }
+
+ // let's fade up by scaling the brightness
+ for(int scale = 0; scale < 128; scale++) {
+ LED.showColor(CRGB(0, 128, 0), NUM_LEDS, scale);
+ delay(10);
+ }
+
+ // let's fade down by scaling the brightness
+ for(int scale = 128; scale > 0; scale--) {
+ LED.showColor(CRGB(0, 128, 0), NUM_LEDS, scale);
+ delay(10);
+ }
}
- // for(int i = 0; i < 64; i++) {
- // memset(leds, i, NUM_LEDS * 3);
- // LED.showRGB((byte*)leds, NUM_LEDS);;
- // // DPRINTLN("waiting");
- // delay(40);
- // }
- // for(int i = 64; i >= 0; i--) {
- // memset(leds, i, NUM_LEDS * 3);
- // LED.showRGB((byte*)leds, NUM_LEDS);;
- // // DPRINTLN("waiting");
- // delay(40);
- // }
-#endif
-} \ No newline at end of file
+}
diff --git a/fastspi.h b/fastspi.h
index f205921f..00747137 100644
--- a/fastspi.h
+++ b/fastspi.h
@@ -1,6 +1,7 @@
#ifndef __INC_FASTSPI_H
#define __INC_FASTSPI_H
+#include "controller.h"
#include "lib8tion.h"
#include "delay.h"