-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcube.ino
112 lines (86 loc) · 2.45 KB
/
cube.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
include "neopixel/neopixel.h"
#define PIXEL_COUNT 6
#define PIXEL_PIN D1
#define BUTTON_PIN A0
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
char publishString[64];
bool buttonHasBeenPressed = false;
int previousButtonVolt = 0;
int victoryDanceDelayValue = 100;
int topIndexPixelOn = -1;
void setup() {
Serial.begin(9600);
strip.begin();
strip.show();
}
void loop() {
checkButtonFinishPress();
if (buttonHasBeenPressed == true) {
incrementLitPixelIndex();
}
updateLitPixels();
finishLoop();
}
void victoryDance() {
strip.clear();
strip.show();
strip.setPixelColor(5, strip.Color(61, 252, 3));
strip.show();
delay(victoryDanceDelayValue);
strip.setPixelColor(0, strip.Color(3, 252, 211));
strip.show();
delay(victoryDanceDelayValue);
strip.setPixelColor(1, strip.Color(3, 181, 252));
strip.show();
delay(victoryDanceDelayValue);
strip.setPixelColor(2, strip.Color(3, 3, 252));
strip.show();
delay(victoryDanceDelayValue);
strip.setPixelColor(3, strip.Color(144, 0, 255));
strip.show();
delay(victoryDanceDelayValue);
strip.setPixelColor(4, strip.Color(242, 41, 229));
strip.show();
delay(200);
}
void updateLitPixels(){
if (topIndexPixelOn != -1) {
for(int i = 0; i <= topIndexPixelOn; i += 1) {
strip.setPixelColor(i, strip.Color(255, 255, 0));
}
strip.show();
}
else {
strip.clear();
}
strip.show();
}
void incrementLitPixelIndex() {
topIndexPixelOn += 1;
sprintf(publishString, "topIndexPixelOn set to %i", topIndexPixelOn);
if (topIndexPixelOn > 5) {
publishString = publishString + " - victoryDance!"
topIndexPixelOn = -1;
victoryDance();
}
Serial.println(publishString);
}
void checkButtonFinishPress() {
int buttonVolt = analogRead(BUTTON_PIN);
// The previousButtonVolt represents a pressed button when > 4000
if (previousButtonVolt > 4000) {
// Button has finished being pressed!
if (buttonVolt < 4000) {
buttonHasBeenPressed = true;
Serial.println("Button has finished being pressed")
}
}
previousButtonVolt = buttonVolt;
}
void finishLoop() {
if (buttonHasBeenPressed == true) {
buttonHasBeenPressed = false;
}
delay(100);
}