Skip to content
Snippets Groups Projects
LEDBehaviours.cpp 1.53 KiB
Newer Older
#include "LEDBehaviours.h"

NumLEDs::NumLEDs(Adafruit_NeoPixel* strip, String name, uint32_t color) :
Matthew's avatar
Matthew committed
	Behaviour(name), _strip(strip), _color(color)
{ }

String NumLEDs::start(String args)
Matthew's avatar
Matthew committed
{
	int val = args.toInt();
	 //Always clear the strip first
	_strip->clear();

	if( val > 0 )
	{
		_strip->fill(_color, 0, val);
	}

	_strip->show();

	return "";
};

char * NumLEDs::args()
{
	return "<int num_leds>";
};
BrightnessLEDs::BrightnessLEDs(Adafruit_NeoPixel* strip, String name, uint32_t hue, uint32_t sat) :
Matthew's avatar
Matthew committed
	Behaviour(name), _strip(strip), _hue(hue), _sat(sat)
{ }

String BrightnessLEDs::start(String args)
Matthew's avatar
Matthew committed
{
	int val = args.toInt();
	_strip->clear();
	_strip->fill(_strip->ColorHSV(_hue,_sat,val));
	_strip->show();

	return "";
};

BreathingLEDs::BreathingLEDs(Adafruit_NeoPixel* strip, String name, uint32_t hue, uint32_t sat) :
Matthew's avatar
Matthew committed
	Behaviour(name), _strip(strip), _hue(hue * 255), _sat(sat)
{ }

char * BrightnessLEDs::args()
{
	return "<int brightness>";
};

void BreathingLEDs::update()
{
	if( _rate <= 0 )
	{
		_strip->fill(0);
		_strip->show();

		return;
	}

	_current = _current + (_rate * _direction);

	if( _current < 0 )
	{
		_current = 0;
		_direction = 1;
	}

	if( _current > 255 * _factor )
	{
		_current = 255 * _factor;
		_direction = -1;
	}

	_strip->fill(_strip->ColorHSV(_hue,_sat,_current / _factor));
	_strip->show();

};

String BreathingLEDs::start(String args)
Matthew's avatar
Matthew committed
{
	_current = 0;
	_direction = 1;
	_running = true;
	int val = args.toInt();
	_rate = val;

	return "";
};

char * BreathingLEDs::args()
{
	return "<int rate (1-255ish)>";
};