Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buck puck integration #10

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=ALA
version=2.3.1
name=ALA-BP
version=2.3.2
author=bportaluri
maintainer=Bruno Portaluri <[email protected]>
sentence=Arduino Light Animation (ALA) library
paragraph=Arduino Light Animation (ALA) is a library for Arduino boards to simplify the development of light animations using LEDs and LED strips.
category=Other
url=https://github.com/bportaluri/ALA
architectures=*
architectures=*
3 changes: 2 additions & 1 deletion src/Ala.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ along with The Arduino ALA library. If not, see
#define ALA_PWM 1
#define ALA_TLC5940 2
#define ALA_WS2812 3
#define ALA_BP 4


////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -254,4 +255,4 @@ float getStepFloat(long t0, long t, float v);
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max);


#endif
#endif
35 changes: 33 additions & 2 deletions src/AlaLed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ void AlaLed::initPWM(int numLeds, byte *pins)
memset(leds, 0, numLeds);
}

void AlaLed::initBP(byte pin)
{
byte *pins_ = (byte *)malloc(1);
pins_[0] = pin;

initBP(1, pins_);
}


void AlaLed::initBP(int numLeds, byte *pins)
{
this->driver = ALA_BP;
this->numLeds = numLeds;
this->pins = pins;

for (int x=0; x<numLeds ; x++)
{
pinMode(pins[x], OUTPUT);
}

// allocate and clear leds array
leds = (byte *)malloc(numLeds);
memset(leds, 0, numLeds);
}

void AlaLed::initTLC5940(int numLeds, byte *pins)
{
this->driver = ALA_TLC5940;
Expand Down Expand Up @@ -89,6 +114,8 @@ void AlaLed::setAnimation(AlaSeq animSeq[])
this->animSeq = animSeq;

// initialize animSeqDuration and animSeqLen variables
currAnim = 0;
lastRefreshTime = 0;
animSeqDuration = 0;
for(animSeqLen=0; animSeq[animSeqLen].animation!=ALA_ENDSEQ; animSeqLen++)
{
Expand Down Expand Up @@ -133,10 +160,14 @@ void AlaLed::runAnimation()
{
(this->*animFunc)();

if(driver==ALA_PWM)
if((driver==ALA_PWM) || (driver==ALA_BP))
{
int offset = 0;
if (driver==ALA_BP)
offset = 255;

for(int i=0; i<numLeds; i++)
analogWrite(pins[i], leds[i]);
analogWrite(pins[i], offset - leds[i]);
}
else if(driver==ALA_TLC5940)
{
Expand Down
12 changes: 11 additions & 1 deletion src/AlaLed.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ class AlaLed
* Initializes LEDs driven by Arduino PWM pins. It be invoked in the setup() function of the main Arduino sketch.
*/
void initPWM(int numLeds, byte *pins);

/**
* Initializes a LED driven by a BuckPuck from an Arduino PWM pin. It be invoked in the setup() function of the main Arduino sketch.
*/
void initBP(byte pin);

/**
* Initializes LEDs driven by BuckPucks from Arduino PWM pins. It be invoked in the setup() function of the main Arduino sketch.
*/
void initBP(int numLeds, byte *pins);

/**
* Initializes LEDs driven by a TLC5940 chip. It be invoked in the setup() function of the main Arduino sketch.
Expand Down Expand Up @@ -117,4 +127,4 @@ class AlaLed

};

#endif
#endif
37 changes: 37 additions & 0 deletions src/AlaLedRgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ void AlaLedRgb::initPWM(int numLeds, byte *pins)
memset(leds, 0, 3*numLeds);
}

void AlaLedRgb::initBP(byte pinRed, byte pinGreen, byte pinBlue)
{
byte *pins_ = (byte *)malloc(3);
pins_[0] = pinRed;
pins_[1] = pinGreen;
pins_[2] = pinBlue;

initBP(1, pins_);
}

void AlaLedRgb::initBP(int numLeds, byte *pins)
{
this->driver = ALA_BP;
this->numLeds = numLeds;
this->pins = pins;

for (int x=0; x<3*numLeds ; x++)
{
pinMode(pins[x], OUTPUT);
}

// allocate and clear leds array
leds = (AlaColor *)malloc(3*numLeds);
memset(leds, 0, 3*numLeds);
}

void AlaLedRgb::initTLC5940(int numLeds, byte *pins)
{
this->driver = ALA_TLC5940;
Expand Down Expand Up @@ -151,6 +177,8 @@ void AlaLedRgb::setAnimation(AlaSeq animSeq[])
this->animSeq = animSeq;

// initialize animSeqDuration and animSeqLen variables
currAnim = 0;
lastRefreshTime = 0;
animSeqDuration = 0;
for(animSeqLen=0; animSeq[animSeqLen].animation!=ALA_ENDSEQ; animSeqLen++)
{
Expand Down Expand Up @@ -233,6 +261,15 @@ bool AlaLedRgb::runAnimation()
neopixels->setPixelColor(i, neopixels->Color((leds[i].r*maxOut.r)>>8, (leds[i].g*maxOut.g)>>8, (leds[i].b*maxOut.b)>>8));

neopixels->show();
}else if(driver==ALA_BP)
{
for(int i=0; i<numLeds; i++)
{
int j = 3*i;
analogWrite(pins[j], 255-((leds[i].r*maxOut.r)>>8));
analogWrite(pins[j+1], 255-((leds[i].g*maxOut.g)>>8));
analogWrite(pins[j+2], 255-((leds[i].b*maxOut.b)>>8));
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/AlaLedRgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class AlaLedRgb

void initPWM(byte pinsRed, byte pinGreen, byte pinBlue);
void initPWM(int numLeds, byte *pins);
void initBP(byte pinsRed, byte pinGreen, byte pinBlue);
void initBP(int numLeds, byte *pins);
void initTLC5940(int numLeds, byte *pins);

/**
Expand Down Expand Up @@ -115,4 +117,4 @@ class AlaLedRgb
};


#endif
#endif