A simple ChaseLight library for Arduino. It should be easy to use for everyone even without any coding experience. All member functions can be called without any argument. Since the delay function is used in the code, the microcontroller can't do anything else then the chaselight. I will create another library for this case.
The time library is implemented WIP.
-
Download the .zip file from GitHub.
-
Insert the library into your Arduino IDE.
- Sketch -> Include Library -> Add .ZIP Library...
-
Include the header in your project .ino file.
#include <ChaseLight.h>- Create a global class object.
ChaseLight Light;- In the Setup function create an array with the output pins in the order from left to right. The init functions needs the size of the array, the array itself and the default delay.
int init( const myByte &size, const myByte *channels, const int &mDelay );void setup( void )
{
const myByte channels[] = {9, 10, 8, 7, 4, 5, 6, 3, 2};
Light.init( sizeof( channels ), channels, 100);
}- In the loop function call one of the chaselight member functions.
void loop(void)
{
Light.flash();
Light.knightRider();
Light.knightRiderMiddle();
Light.fillUp();
Light.fillTo();
Light.move();
}- Create a global class object.
ChaseLightTime Light;- In the Setup function create an array with the output pins in the order from left to right. The init functions needs the size of the array, the array itself and the default delay.
int init( const myByte &size, const myByte *channels, const int &mDelay );In order to process the sequence steps inside the loop. The object needs to create the sequence. That has to happen in the setup function. If needed you can also register buttons. Keep in mind that the Time functionality is still WIP.
void setup( void )
{
const myByte channels[] = {9, 10, 8, 7, 4, 5, 6, 3, 2};
Light.init( sizeof( channels ), channels, 100);
Light.fillUp( 1, 30, START_LEFT, EMPTY_LEFT );
Light.registerButton( 0, &ChaseLightTime::pauseToggle );
Light.registerButton( 1, &ChaseLightTime::stopToggle );
}- In the loop function call the chaselight loopStep member function.
void loop(void)
{
Light.loopStep();
}void setAllChannelsD( const myByte &value );
void flash( const myByte &count = 3, int mDelay = 0 );
void knightRider( const myByte &count = 3, int mDelay = 0, e_setting setTo = START_LEFT );
void knightRiderMiddle( const myByte &count = 3, int mDelay = 0, e_setMiddle setTo = START_INSIDE );
void moveFillUp( const myByte &count = 3, int mDelay = 0, e_setting setTo = START_LEFT, e_empty empty = EMPTY_NONE );
void fillTo( const myByte &count = 3, int mDelay = 0, e_setting setTo = START_LEFT, e_empty empty = EMPTY_NONE );
void move( const myByte &count = 3, int mDelay = 0, e_setting setTo = START_LEFT, e_empty empty = EMPTY_NONE );void flash( const myByte &count = 3, int mDelay = 0 );All connected lights will light up in a loop - turned on and off.
mDelayDelay in miliseconds for switching lights - default = this->mDelay.
countNumber of total loops - default = 3.
returnNothing.
Light.flash();
void knightRider( const myByte &count = 3, int mDelay = 0, e_setting setTo = START_LEFT );One light moving in a loop. Can be customized with first argument setTo.
START_LEFT= light starts left and moves to the right.
START_RIGHT= light starts right and moves to the left.
START_LEFT_INVERT= one light turned off and moves from left to the right.
START_RIGHT_INVERT= one light turned off and moves from left to the right.
setToSetting for changing direction and invert lights default = LEFT.
mDelayDelay in miliseconds for moving lights - default = this->mDelay.
countNumber of total loops - default = 3.
returnNothing.
Light.knightRider( START_LEFT );
Light.knightRider( START_RIGHT );
Light.knightRider( START_LEFT_INVERTED );
Light.knightRider( START_RIGHT_INVERTED );
void knightRiderMiddle( const myByte &count = 3, int mDelay = 0, e_setMiddle setTo = START_INSIDE );Two lights moving from the inside to the outside and then returning back to the inside.
Can be customized with first argument setTo.
START_INSIDE= start in the middle moves to the ends.
START_OUTSIDE= start at the ends and moves to the middle.
START_MIDDLE_INVERTED= start in the middle moves to the ends inverted lights.
START_INSIDe_INVERTED= start at the ends and moves to the middle inverted lights.
setToSetting for changing direction and invert lights default = START_MIDDLE.
mDelayDelay in miliseconds for moving lights - default = this->mDelay.
countNumber of total loops - default = 3.
returnNothing.
Light.knightRiderMiddle( START_INSIDE );
Light.knightRiderMiddle( START_OUTSIDE );
Light.knightRiderMiddle( START_INSIDE_INVERTED );
Light.knightRiderMiddle( START_OUTSIDE_INVERTED );
void moveFillUp( const myByte &count = 3, int mDelay = 0, e_setting setTo = START_LEFT, e_empty empty = EMPTY_NONE );One light moving and filling up till all lights turned to !value. Can be customized with first argument setTo and second argument setEmpty.
START_LEFT= light starts left and moves to the right.
START_RIGHT= light starts right and moves to the left.
START_LEFT_INVERT= one light turned off and moves from left to the right.
START_RIGHT_INVERT= one light turned off and moves from left to the right.
EMPTY_NONE= will not be emptied.
EMPTY_LEFT= lights will be emptied moving left.
EMPTY_RIGHT= lights will be emptied moving right.
setToSetting for changing direction and invert lights default = START_LEFT.
setEmptySetting for emptying the filled lights. default = EMPTY_NONE.
mDelayDelay in miliseconds for moving lights - default = this->mDelay.
countNumber of total loops - default = 3.
returnNothing.
Light.fillUp( START_LEFT, EMPTY_NONE );
Light.fillUp( START_RIGHT, EMPTY_NONE );
Light.fillUp( START_LEFT_INVERTED, EMPTY_NONE );
Light.fillUp( START_RIGHT_INVERTED, EMPTY_NONE );
Light.fillUp( START_LEFT, EMPTY_LEFT );
Light.fillUp( START_RIGHT, EMPTY_LEFT );
Light.fillUp( START_LEFT_INVERTED, EMPTY_LEFT );
Light.fillUp( START_RIGHT_INVERTED, EMPTY_LEFT );
Light.fillUp( START_LEFT, EMPTY_RIGHT );
Light.fillUp( START_RIGHT, EMPTY_RIGHT );
Light.fillUp( START_LEFT_INVERTED, EMPTY_RIGHT );
Light.fillUp( START_RIGHT_INVERTED, EMPTY_RIGHT );
void fillTo( const myByte &count = 3, int mDelay = 0, e_setting setTo = START_LEFT, e_empty empty = EMPTY_NONE );One light after another turing to !value till all lights turned to !value.
Can be customized with first argument setTo and second argument setEmpty.
START_LEFT= light starts left and fills to the right.
START_RIGHT= light starts right and fills to the left.
START_LEFT_INVERT= one light turned off and empties from left to the right.
START_RIGHT_INVERT= one light turned off and empties from left to the right.
EMPTY_NONE= will not be emptied.
EMPTY_LEFT= lights will be emptied from left.
EMPTY_RIGHT= lights will be emptied from right.
setToSetting for changing direction and invert lights default = START_LEFT.
setEmptySetting for emptying the filled lights. default = EMPTY_NONE.
mDelayDelay in miliseconds for moving lights - default = this->mDelay.
countNumber of total loops - default = 3.
returnNothing.
Light.fillTo( START_LEFT, EMPTY_NONE );
Light.fillTo( START_RIGHT, EMPTY_NONE );
Light.fillTo( START_LEFT_INVERTED, EMPTY_NONE );
Light.fillTo( START_RIGHT_INVERTED, EMPTY_NONE );
Light.fillTo( START_LEFT, EMPTY_LEFT );
Light.fillTo( START_RIGHT, EMPTY_LEFT );
Light.fillTo( START_LEFT_INVERTED, EMPTY_LEFT );
Light.fillTo( START_RIGHT_INVERTED, EMPTY_LEFT );
Light.fillTo( START_LEFT, EMPTY_RIGHT );
Light.fillTo( START_RIGHT, EMPTY_RIGHT );
Light.fillTo( START_LEFT_INVERTED, EMPTY_RIGHT );
Light.fillTo( START_RIGHT_INVERTED, EMPTY_RIGHT );
void move( const myByte &count = 3, int mDelay = 0, e_setting setTo = START_LEFT, e_empty empty = EMPTY_NONE );
































