void Firefly::go_full_color(int r_g_or_b)
{
    unsigned char full_color[3];
    unsigned char glow_color[3];
    unsigned char original_color[3] = {_rgb_color[0], _rgb_color[1], _rgb_color[2]};

    for(int x = 0; x < 3; x++) {
        if(x == r_g_or_b) {
            full_color[x] = 255;
            glow_color[x] = 25;
        }
        else {
            full_color[x] = 0;
            glow_color[x] = 0;
        }
    }

    int num_glows = random(5,10);

    for(int x = 0; x < num_glows; x++) {
        fade_to(full_color, 4);
        fade_to(glow_color, 4);
    }

    fade_to(original_color, 2);
}
Beispiel #2
0
static void wobble(void) {
	uint8_t cur = pwm_get();
	int8_t delta = (cur > WOBBLE_DELTA) ? (-WOBBLE_DELTA) : WOBBLE_DELTA;

	for(uint8_t i = 0; i < 3; i++) {
		fade_to(cur + delta, WOBBLE_DELAY);
		fade_to(cur, WOBBLE_DELAY);
	}
}
/* 
blinking the firefly :

my basic concept is that fireflies fade up at different speeds, then hold that glow
for a random period of time, then fade down at a speed quicker then they faded up.

also, on occasion - they get real bright in the middle briefly.
*/
void Firefly::firefly_blink()
{
    // first select a color to light up the firefly with
    boolean color_ok = false;
    unsigned char red, green, blue;

    /* 
    i do this to keep the overall value down so they don't
    all come out white
    */
    while(!color_ok) {
        red = random(0,255);
        green = random(0,255);
        blue = random(0,255);

        if(red + green + blue < _max_color_value) {
            color_ok = true;
        }
    }

    // set the delays
    int fade_up_speed = random(4,15);
    int hold_delay = random(0,500);
    int fade_down_speed = random(1,fade_up_speed);

                                                  // light up the firefly
    fade_to(red, green, blue, fade_up_speed);

    delay(random(1,500));

    // do random event on occasion

    int event_trigger = random(1,20);

    if(event_trigger == 5) {
        burst();
    }

    if(event_trigger == 10) {
        sparkle();
    }

    if(event_trigger == 15) {
        go_full_color(random(0,3));
    }

    if(event_trigger == 12 || event_trigger == 6) {
        delay(random(300,800));
    }

    fade_to(0 , 0 ,0 , fade_down_speed);
}
void Firefly::sparkle()
{
    unsigned char original_color[3] = {_rgb_color[0], _rgb_color[1], _rgb_color[2]};

    int num_sparkles = random(4,14);

    for(int x = 0; x < num_sparkles; x++) {
        fade_to(original_color[1],original_color[2],original_color[3],1);
        fade_to(original_color[2],original_color[3],original_color[1],1);
        fade_to(original_color[3],original_color[1],original_color[2],1);
    }

    fade_to(original_color,1);
}
Beispiel #5
0
void control_LEDs(const std::vector<uint16_t>& led_list) {
	// first set up the random-number-generators:
	std::default_random_engine generator(
		static_cast<unsigned long>(std::chrono::system_clock::now().time_since_epoch().count()) );
	std::uniform_int_distribution<useconds_t> sleep_time_distribution(
			settings::min_sleep_time, settings::max_sleep_time);
	std::uniform_int_distribution<useconds_t> fade_time_distribution(
			settings::min_fade_time, settings::max_fade_time);
	std::uniform_int_distribution<size_t> color_distribution(0, settings::colorset.size() - 1);
	
	// and now start the actual work:
	vlpp::rgba_color last_color;
	while(true){
		if(settings::thread_return_flag){
			return;
		}
		vlpp::rgba_color tmp = settings::colorset.at(color_distribution(generator));
		if(tmp == last_color){
			continue;
		}
		fade_to(led_list, fade_time_distribution(generator), last_color, tmp);
		last_color = tmp;
		usleep (sleep_time_distribution(generator));
	}
}
void Firefly::burst()
{
    unsigned char burst_color[3];
    unsigned char original_color[3] = {_rgb_color[0], _rgb_color[1], _rgb_color[2]};

    for(int x = 0; x < 3; x++) {
        if(_rgb_color[x] == highest_rgb_value()) {
            burst_color[x] = 255;
        }
        else {
            burst_color[x] = _rgb_color[x];
        }
    }

    fade_to(burst_color, 2);
    fade_to(original_color, 2);
}
void Firefly::fade_to(unsigned char color[], int speed)
{
    fade_to(color[0], color[1], color[2], speed);
}
Beispiel #8
0
void main(void) {
	uint32_t limit;

	gpio_init();
	pwm_init();
	systick_init();

	pwm_set(0);

	while(1) {
wait:
		limit = 10;
		while(!get_switch())
			;

		fade_to(PWM_MAX, 5);
		delay_ticks(RELEASE_TIME);

start:
		if(limit > 120)
			limit = 120;

		for(uint32_t i = 0; i < limit * 60 * 100; i++) {
			uint32_t cnt = 0;
			while(get_switch()) {
				cnt++;

				if(cnt > 300) {
					limit = 60;
					strobe();

					delay_ticks(2*RELEASE_TIME);
					goto start;
				}

				delay_ticks(10);
			}

			if(cnt) {
				fade_to(0, 5);
				goto wait;
			}

			delay_ticks(10);
		}

		wobble();

		for(uint32_t i = 0; i < 30 * 100; i++) {
			uint32_t cnt = 0;
			while(get_switch()) {
				cnt++;

				if(cnt > 300) {
					limit = 60;
					strobe();

					delay_ticks(2*RELEASE_TIME);
					goto start;
				}

				delay_ticks(10);
			}

			if(cnt) {
				limit += limit;
				delay_ticks(1000);
				goto start;
			}

			delay_ticks(10);
		}

		fade_to(0, 30);
	}
}