-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircuit-playground-bauble.ino
78 lines (66 loc) · 2.67 KB
/
circuit-playground-bauble.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <Adafruit_CircuitPlayground.h>
#include "twinkleIntensityFrame.h"
#include "colourBrightnessModifier.h"
#include "nutcrackerPattern.h"
#include "harkTheHerald.h"
void setup() {
CircuitPlayground.begin();
CircuitPlayground.clearPixels();
CircuitPlayground.setBrightness(35);
}
void loop() {
// Generate twinkle LED offsets and set twinkle constants for this loop
const int twinkleMinMaxHoldFrames = 200;
const int twinkleHighestNumberedFrame = highestNumberedFrame(twinkleMinMaxHoldFrames);
// Generate a random offset starting frame for each LED
int offsets[10] = {};
for (int i = 0; i <= 9; i++) {
offsets[i] = random(0, 500);
}
// (1) Cool white twinkle
// For each frame of animation (1)
for (int i = 0; i <= 3000; i++) {
// For each LED
for (int j = 0; j <= 9; j++) {
int myCurrentFrame = (i + offsets[j]) % twinkleHighestNumberedFrame;
byte myCurrentIntensity = intensityAtFrame(myCurrentFrame, twinkleMinMaxHoldFrames);
CircuitPlayground.setPixelColor(j, modifiedColourComponent(180, myCurrentIntensity), modifiedColourComponent(180, myCurrentIntensity), modifiedColourComponent(255, myCurrentIntensity));
}
}
// (2) Nutcracker flash (r/g/w)
doNutcrackerFlash();
// (3) Warm white twinkle
// For each frame of animation (1)
for (int i = 0; i <= 3000; i++) {
// For each LED
for (int j = 0; j <= 9; j++) {
int myCurrentFrame = (i + offsets[j]) % twinkleHighestNumberedFrame;
byte myCurrentIntensity = intensityAtFrame(myCurrentFrame, twinkleMinMaxHoldFrames);
CircuitPlayground.setPixelColor(j, modifiedColourComponent(255, myCurrentIntensity), modifiedColourComponent(220, myCurrentIntensity), modifiedColourComponent(50, myCurrentIntensity));
}
}
// (2) Nutcracker flash (r/g/w)
doNutcrackerFlash();
// (4) Rainbow cycle
// Based on https://github.com/adafruit/Adafruit_CircuitPlayground/blob/master/examples/mega_demo/RainbowCycleDemo.h
for(int i = 0; i <= 3000; i++) {
// Make an offset based on the current millisecond count scaled by the current speed.
uint32_t offset = millis() / 10;
// Loop through each pixel and set it to an incremental color wheel value.
for(int j = 0; j < 10; j++) {
CircuitPlayground.setPixelColor(j, CircuitPlayground.colorWheel(((j * 256 / 10) + offset) & 255));
}
}
// (2) Nutcracker flash (r/g/w)
doNutcrackerFlash();
// if switch on, play music on this loop
bool slideSwitch = CircuitPlayground.slideSwitch();
if (slideSwitch) {
for(int i = 0; i <= 9; i++) {
CircuitPlayground.setPixelColor(i, 0, 255, 255);
}
doHarkTheHerald();
// (2) Nutcracker flash (r/g/w)
doNutcrackerFlash();
}
}