-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchristmas.ino
57 lines (41 loc) · 1.03 KB
/
christmas.ino
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
#include "sine_fade.h"
#include "even_odd.h"
#include "binary_count.h"
#include "twinkle.h"
void (*effects[4]) (int*, int*) = {&sine_fade, &binary_count, &even_odd, &twinkle};
volatile int effect_index;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
randomSeed(analogRead(0));
pinMode(2, INPUT_PULLUP);
attachInterrupt(0, next_effect, RISING);
effect_index = 0;
}
void loop() {
display_effect(effect_index);
}
void next_effect()
{
if (effect_index == 3){
effect_index = 0;
}else{
effect_index++;
}
}
void display_effect(int effect) {
// put your main code here, to run repeatedly:
int led_values[6];
int tick_delay;
effects[effect_index](led_values, &tick_delay);
write_led_values(led_values);
delay(tick_delay);
}
void write_led_values(int *led_values){
analogWrite(3, led_values[0]);
analogWrite(5, led_values[1]);
analogWrite(6, led_values[2]);
analogWrite(9, led_values[3]);
analogWrite(10, led_values[4]);
analogWrite(11, led_values[5]);
}