-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathColors.cpp
109 lines (94 loc) · 1.7 KB
/
Colors.cpp
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
#include <Arduino.h>
#include "Colors.h"
#include "Adafruit_NeoPixel.h"
#define LED_PIN 8
#define NUM_PIXELS 16
Adafruit_NeoPixel pixels(NUM_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
void initColors()
{
pixels.begin();
}
void setPixel(int pixel, byte red, byte green, byte blue)
{
pixels.setPixelColor(pixel, pixels.Color(red, green, blue));
}
void setAll(byte red, byte green, byte blue)
{
for (int i = 0; i < NUM_PIXELS; i++)
{
setPixel(i, red, green, blue);
}
pixels.show();
}
void turnOff()
{
setAll(0, 0, 0);
}
void showColorWhite()
{
setAll(255, 255, 255);
}
void showColorRed()
{
setAll(255, 0, 0);
}
void showColorGreen()
{
setAll(0, 255, 0);
}
void showColorBlue()
{
setAll(0, 0, 255);
}
void showColorYellow()
{
setAll(255, 140, 0);
}
void showColorPurple()
{
setAll(80, 0, 80);
}
void showCustomColor(int r, int g, int b)
{
setAll(r, g, b);
}
void blinkColor(int delayValue, int color)
{
for (int i = 0; i < 20; i++)
{
selectColorByIndexMode(color);
delay(delayValue);
turnOff();
delay(delayValue);
}
}
void selectColorByIndexMode(int colorIndex)
{
switch (colorIndex)
{
case INDEX_COLOR_RED:
showColorRed();
break;
case INDEX_COLOR_GREEN:
showColorGreen();
break;
case INDEX_COLOR_BLUE:
showColorBlue();
break;
case INDEX_COLOR_PURPLE:
showColorPurple();
break;
case INDEX_COLOR_YELLOW:
showColorYellow();
break;
case INDEX_COLOR_WHITE:
showColorWhite();
break;
case INDEX_TURN_OFF:
turnOff();
break;
default:
turnOff();
break;
}
}