Skip to content

Commit

Permalink
Add end() method
Browse files Browse the repository at this point in the history
Stop timer and restore SPCR register.
Now, it is possible to use correctly HL1606strip after HL1606stripPWM.
  • Loading branch information
hugokernel committed Aug 27, 2013
1 parent 20cac9a commit 1c3639a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions HL1606stripPWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ void HL1606stripPWM::begin(void) {
#endif
}

void HL1606stripPWM::end(void) {
#if defined(__AVR_ATmega32U4__)
TIMSK3 = (0 << OCIE3A);
#else
TIMSK2 = (0 << OCIE2A);
#endif

SPCR = _spcr;
}


void HL1606stripPWM::timerinit(void) {
// calculate how long it will take to pulse one strip down
Expand Down Expand Up @@ -145,6 +155,7 @@ void HL1606stripPWM::SPIinit(void) {
// set up high speed SPI for 500 KHz
// The datasheet says that the clock pulse width must be > 300ns. Two pulses > 600ns that would
// make the max frequency 1.6 MHz - fat chance getting that out of HL1606's though
_spcr = SPCR;
SPCR = _BV(SPE) | _BV(MSTR); // enable SPI master mode
setSPIdivider(SPIspeedDiv); // SPI clock is FCPU/32 = 500 Khz for most arduinos

Expand Down
3 changes: 3 additions & 0 deletions HL1606stripPWM.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

class HL1606stripPWM {
private:
uint8_t _spcr;

// How many bits of color per LED for PWM?
// if its set to 2 bits/LED that means 6 bit color (since there are 3 LEDs)
// if its set to 3 bits/LED that equals 9 bit color
Expand Down Expand Up @@ -65,6 +67,7 @@ class HL1606stripPWM {
public:
HL1606stripPWM(uint8_t nLEDs, uint8_t latch);
void begin(void);
void end(void);
void setLEDcolorPWM(uint8_t n, uint8_t r, uint8_t g, uint8_t b);
uint8_t numLEDs(void);

Expand Down

0 comments on commit 1c3639a

Please sign in to comment.