-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLedStrip.ino
172 lines (149 loc) · 3.4 KB
/
LedStrip.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Couleurs de LEDs
int ledR = 5;
int ledV = 3;
int ledB = 6;
// Switch
int sw = 2;
// Bouton poussoir
int bp = 7;
// Potentiomètre
int pot = A0;
unsigned int valR=0;
unsigned int valV=0;
unsigned int valB=0;
unsigned int choix=0;
unsigned int valeur=0;
unsigned int s=0;
int mode = 0;
int nouveauMode = 0;
double teinte=0;
int k=0;
int x=0;
unsigned int valR_potMode=0;
unsigned int valV_potMode=0;
unsigned int valB_potMode=0;
void setup() {
pinMode(ledR, OUTPUT);
pinMode(ledV, OUTPUT);
pinMode(ledB, OUTPUT);
pinMode(sw, INPUT);
Serial.begin(115200);
Serial.setTimeout(4);
valR = 255;
valV = 255;
valB = 255;
valR_potMode = 255;
valV_potMode = 0;
valB_potMode = 0;
analogWrite( ledR , valR );
analogWrite( ledV , valV );
analogWrite( ledB , valB );
}
void loop(){
nouveauMode = digitalRead( sw ); // == HIGH ? 1 : 0;
if( mode != nouveauMode )
{
mode = nouveauMode;
if( mode == 0 )
{
analogWrite( ledR , valR_potMode );
analogWrite( ledV , valV_potMode );
analogWrite( ledB , valB_potMode );
}
else
{
analogWrite( ledR , valR );
analogWrite( ledV , valV );
analogWrite( ledB , valB );
}
}
if( mode == 1 )
{
s = (unsigned int) Serial.parseInt();
if( s != 0 )
{
//Serial.print( "s" );
//Serial.println( s );
//valeur = ( s & 255 ) % 256;
valeur = ( s << 8 ) >> 8;
choix = ( s & 65280 ) >> 8;
//Serial.print( "choix" );
//Serial.println( choix );
if( choix == 1 )
{
//Serial.print( "rouge" );
//Serial.println( valeur );
valR = valeur;
analogWrite( ledR , (int)( floor( valR * (double)analogRead(pot) / 1023.0 ) ) );
}
else if( choix == 2 )
{
//Serial.print( "vert" );
//Serial.println( valeur );
valV = valeur;
analogWrite( ledV , (int)( floor( valV * (double)analogRead(pot) / 1023.0 ) ) );
}
else if( choix == 3 )
{
//Serial.print( "bleu" );
//Serial.println( valeur );
valB = valeur;
analogWrite( ledB , (int)( floor( valB * (double)analogRead(pot) / 1023.0 ) ) );
}
}
}
else
{
teinte = ( (double)analogRead( pot ) / 1023.0 * 6.0 );
k = (int)( floor( teinte ) );
k = ( k%6 + 6 ) % 6;
x = ( (int)floor( (teinte - (double)k) *255.0) % 255 + 255 ) % 255;
valR_potMode = 0;
valV_potMode = 0;
valB_potMode = 0;
// ROUGE VERS JAUNE
if( k == 0 )
{
valR_potMode = 255;
valV_potMode = x;
}
// JAUNE VERS VERT
else if( k == 1 )
{
valR_potMode = 255 - x;
valV_potMode = 255;
}
// VERT VERS CYAN
else if( k == 2 )
{
valV_potMode = 255;
valB_potMode = x;
}
// CYAN VERS BLEU
else if( k == 3 )
{
valV_potMode = 255 - x;
valB_potMode = 255;
}
// BLEU VERS MAGENTA
else if( k == 4 )
{
valR_potMode = x;
valB_potMode = 255;
}
// MAGENTA VERS ROUGE
else
{
valR_potMode = 255;
valB_potMode = 255 - x;
}
analogWrite( ledR , valR_potMode );
analogWrite( ledV , valV_potMode );
analogWrite( ledB , valB_potMode );
/*
Serial.print( "pot : " );
Serial.println( ( (double)analogRead( pot ) / 1023.0 * 100.0 ) );
*/
//Serial.println( "pot : " );
}
}