-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_rgb_fade_with_function.ino
More file actions
124 lines (97 loc) · 1.94 KB
/
4_rgb_fade_with_function.ino
File metadata and controls
124 lines (97 loc) · 1.94 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
/*
Morse code sheet: https://drive.google.com/file/d/1liBuEK5mu3E04ymCv_On7b9cEDAkBJO1/view
Challenges:
1) Create function to fade RGB
2) Colors of Rainbow fading style
Color guide: https://www.rapidtables.com/web/color/RGB_Color.html
*/
#define RED 3
#define BLUE 5
#define GREEN 6
int counter;
void setup() {
pinMode(RED,OUTPUT); //- RED
pinMode(BLUE,OUTPUT); //- BLUE
pinMode(GREEN,OUTPUT); //- GREEN
pinMode(7,OUTPUT);
}
void dot() {
digitalWrite(7,HIGH);
delay(100);
digitalWrite(7,LOW);
delay(100);
}
void dash() {
digitalWrite(7,HIGH);
delay(300);
digitalWrite(7,LOW);
delay(100);
}
void rgbOff() {
analogWrite(RED,0);
analogWrite(BLUE,0);
analogWrite(GREEN,0);
}
void rgbRed() {
analogWrite(RED,255);
analogWrite(BLUE,0);
analogWrite(GREEN,0);
}
void rgbBlue() {
analogWrite(RED,0);
analogWrite(BLUE,255);
analogWrite(GREEN,0);
}
void rgbGreen() {
analogWrite(RED,0);
analogWrite(BLUE,0);
analogWrite(GREEN,255);
}
void rgbOrange() {
analogWrite(RED,255);
analogWrite(GREEN,205);
analogWrite(BLUE,0);
}
void rgbYellow() {
analogWrite(RED,222);
analogWrite(GREEN,255);
analogWrite(BLUE,0);
}
void rgbIndigo() {
analogWrite(RED,0);
analogWrite(GREEN,247);
analogWrite(BLUE,255);
}
void rgbViolet() {
analogWrite(RED,179);
analogWrite(GREEN,0);
analogWrite(BLUE,255);
}
void rgbFade(int color,int startValue, int endValue) {
int counter;
if (startValue < endValue) {
//- increment
counter = startValue;
while (counter <= endValue) {
analogWrite(color,counter);
counter = counter + 1;
delay(20);
}
}
if (startValue > endValue) {
//- decrement
counter = startValue;
while (counter >= endValue) {
analogWrite(color,counter);
counter = counter - 1;
delay(20);
}
}
}
void loop() {
rgbOff();
rgbFade(RED,0,255);
rgbFade(BLUE,0,255);
rgbFade(RED,255,0);
rgbFade(BLUE,255,0);
}