Skip to content

Kromolux/Arduino_ChaseLight

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MyKro_ChaseLight

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.

How to use this library?

  1. Download the .zip file from GitHub.

  2. Insert the library into your Arduino IDE.

    • Sketch -> Include Library -> Add .ZIP Library...
  3. Include the header in your project .ino file.

#include <ChaseLight.h>

Delay version

  1. Create a global class object.
ChaseLight Light;
  1. 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);
}
  1. 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();
}

Time version

  1. Create a global class object.
ChaseLightTime Light;
  1. 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 );
}
  1. In the loop function call the chaselight loopStep member function.
void loop(void)
{
	Light.loopStep();
}

What is inside?

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 );

flash

void	flash( const myByte &count = 3, int mDelay = 0 );

All connected lights will light up in a loop - turned on and off.
mDelay Delay in miliseconds for switching lights - default = this->mDelay.
count Number of total loops - default = 3.
return Nothing.

Light.flash();

knightRider

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.
setTo Setting for changing direction and invert lights default = LEFT.
mDelay Delay in miliseconds for moving lights - default = this->mDelay.
count Number of total loops - default = 3.
return Nothing.

Light.knightRider( START_LEFT );

Light.knightRider( START_RIGHT );

Light.knightRider( START_LEFT_INVERTED );

Light.knightRider( START_RIGHT_INVERTED );

knightRiderMiddle

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.
setTo Setting for changing direction and invert lights default = START_MIDDLE.
mDelay Delay in miliseconds for moving lights - default = this->mDelay.
count Number of total loops - default = 3.
return Nothing.

Light.knightRiderMiddle( START_INSIDE );

Light.knightRiderMiddle( START_OUTSIDE );

Light.knightRiderMiddle( START_INSIDE_INVERTED );

Light.knightRiderMiddle( START_OUTSIDE_INVERTED );

fillUp

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.
setTo Setting for changing direction and invert lights default = START_LEFT.
setEmpty Setting for emptying the filled lights. default = EMPTY_NONE.
mDelay Delay in miliseconds for moving lights - default = this->mDelay.
count Number of total loops - default = 3.
return Nothing.

EMPTY_NONE

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 );

EMPTY_LEFT

Light.fillUp( START_LEFT, EMPTY_LEFT );

Light.fillUp( START_RIGHT, EMPTY_LEFT );

16fillUp_cropped

Light.fillUp( START_LEFT_INVERTED, EMPTY_LEFT );

17fillUp_cropped

Light.fillUp( START_RIGHT_INVERTED, EMPTY_LEFT );

18fillUp_cropped

EMPTY_RIGHT

Light.fillUp( START_LEFT, EMPTY_RIGHT );

19fillUp_cropped

Light.fillUp( START_RIGHT, EMPTY_RIGHT );

20fillUp_cropped

Light.fillUp( START_LEFT_INVERTED, EMPTY_RIGHT );

21fillUp_cropped

Light.fillUp( START_RIGHT_INVERTED, EMPTY_RIGHT );

22fillUp_cropped

fillTo

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.
setTo Setting for changing direction and invert lights default = START_LEFT.
setEmpty Setting for emptying the filled lights. default = EMPTY_NONE.
mDelay Delay in miliseconds for moving lights - default = this->mDelay.
count Number of total loops - default = 3.
return Nothing.

EMPTY_NONE

Light.fillTo( START_LEFT, EMPTY_NONE );

23fillTo_cropped

Light.fillTo( START_RIGHT, EMPTY_NONE );

24fillTo_cropped

Light.fillTo( START_LEFT_INVERTED, EMPTY_NONE );

25fillTo_cropped

Light.fillTo( START_RIGHT_INVERTED, EMPTY_NONE );

26fillTo_cropped

EMPTY_LEFT

Light.fillTo( START_LEFT, EMPTY_LEFT );

27fillTo_cropped

Light.fillTo( START_RIGHT, EMPTY_LEFT );

28fillTo_cropped

Light.fillTo( START_LEFT_INVERTED, EMPTY_LEFT );

29fillTo_cropped

Light.fillTo( START_RIGHT_INVERTED, EMPTY_LEFT );

30fillTo_cropped

EMPTY_RIGHT

Light.fillTo( START_LEFT, EMPTY_RIGHT );

31fillTo_cropped

Light.fillTo( START_RIGHT, EMPTY_RIGHT );

32fillTo_cropped

Light.fillTo( START_LEFT_INVERTED, EMPTY_RIGHT );

33fillTo_cropped

Light.fillTo( START_RIGHT_INVERTED, EMPTY_RIGHT );

34fillTo_cropped

move

void	move( const myByte &count = 3, int mDelay = 0, e_setting setTo = START_LEFT, e_empty empty = EMPTY_NONE );

EMPTY_NONE

EMPTY_LEFT

EMPTY_RIGHT

About

Arduino_ChaseLight

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published