aboutsummaryrefslogtreecommitdiff
path: root/software/software.ino
blob: 4cea2b4fba0220330793a46ae2e470e73f044719 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "software.h"
#include "consts.h"
#include "effects.h"
#include "scan.h"

unsigned long frame_time_millis;
bool led_state[64];
bool scan_enable = true;
#ifndef SLIDESHOW_DURATION
unsigned long slideshow_length_total;
#endif

void setup() {
	pinMode(PINOUT_SER, OUTPUT);
	pinMode(PINOUT_SCK, OUTPUT);
	pinMode(PINOUT_LCK, OUTPUT);

	pinMode(PINOUT_NOISE, INPUT); // random noise voor RNG
	randomSeed(analogRead(PINOUT_NOISE));

	#ifdef DEBUG
	Serial.begin(CONFIG_SERIAL_BAUD);
	Serial.println("startup");
	#endif

	#ifndef SLIDESHOW_DURATION
	for(int i = 0; i < SLIDESHOW_SIZE; i++)
		slideshow_length_total += slideshow_lengths[i];
	#endif

	frame_time_millis = (int)((double) 1000 / (double) CONFIG_FRAMERATE);
}

void loop() {
	unsigned long current_time = millis();

	#ifdef SLIDESHOW_DURATION
	unsigned long slide_time = current_time % SLIDESHOW_DURATION;
	unsigned int  slide_index = (current_time / SLIDESHOW_DURATION) % SLIDESHOW_SIZE;
	#else
	unsigned long slide_time = current_time % slideshow_length_total;
	unsigned int  slide_index = 0;
	unsigned long slide_sum = 0;
	for(int i = 0; i < SLIDESHOW_SIZE; i++) {
		slide_sum += slideshow_lengths[i];
		if (slide_time >= slide_sum) continue;
		slide_index = i;
		slide_time -= slide_sum - slideshow_lengths[i];
		break;
	}
	#endif

	#ifdef DEBUG
	print_ani_debug(slide_index, slide_time);
	#endif
	slideshow_effects[slide_index](slide_time);

	if (scan_enable) scan();
}