Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix example code, block instead double buffering, spi optimization

  • Loading branch information...
commit 4f0254b8f8498dd7583d0c76264837794c642761 1 parent 79716d2
Michael Vogt authored

Showing 2 changed files with 19 additions and 11 deletions. Show diff stats Hide diff stats

  1. +16 8 Neophob_LPD6803.cpp
  2. +3 3 examples/lpd6803Spi/lpd6803Spi.ino
24 Neophob_LPD6803.cpp
@@ -17,6 +17,7 @@ static uint8_t isDirty;
17 17 static uint16_t prettyUglyCopyOfNumPixels;
18 18 static uint16_t *pData;
19 19 static uint16_t *pDataStart;
  20 +volatile unsigned char nState=1;
20 21
21 22 // Constructor for use with hardware SPI (specific clock/data pins):
22 23 Neophob_LPD6803::Neophob_LPD6803(uint16_t n) {
@@ -26,6 +27,11 @@ Neophob_LPD6803::Neophob_LPD6803(uint16_t n) {
26 27 pDataStart = pixels;
27 28 isDirty = 0;
28 29 cpumax = 70;
  30 +
  31 + //clear buffer
  32 + for (int i=0; i < numLEDs; i++) {
  33 + setPixelColor(i,0);
  34 + }
29 35 }
30 36
31 37 //Interrupt routine.
@@ -33,11 +39,11 @@ Neophob_LPD6803::Neophob_LPD6803(uint16_t n) {
33 39 //In your code, set global Sendmode to 0 to re-send the data to the pixels
34 40 //Otherwise it will just send clocks.
35 41 static void isr() {
36   - static unsigned char nState=1;
  42 + //static unsigned char nState=1;
37 43 static unsigned char indx=0;
38 44
39   - if(nState==1) {//send clock and check for color update (isDirty)
40   - SPI_A(0); //maybe, move at the end of the startSPI() method
  45 + if(nState==1) {//send clock and check for color update (isDirty)
  46 + //SPI_A(0); //maybe, move at the end of the startSPI() method
41 47 if (isDirty==1) { //must we update the pixel value
42 48 nState = 0;
43 49 isDirty = 0;
@@ -94,13 +100,15 @@ void Neophob_LPD6803::startSPI(void) {
94 100 SPI.begin();
95 101 SPI.setBitOrder(MSBFIRST);
96 102 SPI.setDataMode(SPI_MODE0);
97   - SPI.setClockDivider(SPI_CLOCK_DIV8); // 2 MHz
98   - // WS2801 datasheet recommends max SPI clock of 2 MHz, and 50 Ohm
  103 +// SPI.setClockDivider(SPI_CLOCK_DIV8); // 2 MHz
  104 + SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz
  105 + // LPD6803 can handle a data/PWM clock of up to 25 MHz, and 50 Ohm
99 106 // resistors on SPI lines for impedance matching. In practice and
100 107 // at short distances, 2 MHz seemed to work reliably enough without
101 108 // resistors, and 4 MHz was possible with a 220 Ohm resistor on the
102 109 // SPI clock line only. Your mileage may vary. Experiment!
103   - // SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz
  110 +
  111 + SPI_A(0); //maybe, move at the end of the startSPI() method
104 112 }
105 113
106 114 uint16_t Neophob_LPD6803::numPixels(void) {
@@ -122,7 +130,7 @@ void Neophob_LPD6803::setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b)
122 130 functions in reverse (high to low pixel index), then the two can
123 131 operate together relatively efficiently with only minimal blocking
124 132 and no second pixel buffer required. */
125   - //while(nState==0); enable me
  133 + while(nState==0);
126 134
127 135 uint16_t data = g & 0x1F;
128 136 data <<= 5;
@@ -144,7 +152,7 @@ void Neophob_LPD6803::setPixelColor(uint16_t n, uint16_t c) {
144 152 functions in reverse (high to low pixel index), then the two can
145 153 operate together relatively efficiently with only minimal blocking
146 154 and no second pixel buffer required. */
147   - //while(nState==0); enable me
  155 + while(nState==0);
148 156
149 157 pixels[n] = 0x8000 | c;
150 158 }
6 examples/lpd6803Spi/lpd6803Spi.ino
@@ -28,9 +28,9 @@ void setup() {
28 28
29 29
30 30 void loop() {
31   - colorWipe(Color(63, 0, 0), 50);
32   - colorWipe(Color(0, 63, 0), 50);
33   - colorWipe(Color(0, 0, 63), 50);
  31 + colorWipe(Color(31, 0, 0), 50);
  32 + colorWipe(Color(0, 31, 0), 50);
  33 + colorWipe(Color(0, 0, 31), 50);
34 34
35 35 rainbowCycle(50);
36 36

0 comments on commit 4f0254b

Please sign in to comment.
Something went wrong with that request. Please try again.