-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathledControl.ino
More file actions
54 lines (48 loc) · 1.1 KB
/
ledControl.ino
File metadata and controls
54 lines (48 loc) · 1.1 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
const int PIN_R = 5;
const int PIN_G = 9;
const int PIN_B = 11;
const int POT_R = A1;
const int POT_G = A3;
const int POT_B = A5;
const int DEBOUNCE_READS=10;
const int DEBOUNCE_DELAY=50; //miliseconds
const boolean DEBUG=true;
const int DEBUG_DELAY=500;
void setup() {
// put your setup code here, to run once:
pinMode(PIN_R, OUTPUT);
pinMode(PIN_G, OUTPUT);
pinMode(PIN_B, OUTPUT);
pinMode(POT_R, INPUT);
pinMode(POT_G, INPUT);
pinMode(POT_B, INPUT);
if (DEBUG) Serial.begin(9600);
}
void loop() {
switchOne(POT_R, PIN_R);
switchOne(POT_G, PIN_G);
switchOne(POT_B, PIN_B);
}
void switchOne(int pinIn, int pinOut) {
int readSum = 0;
for (int i = 0; i < DEBOUNCE_READS; ++i) {
delay(DEBOUNCE_DELAY);
readSum += analogRead(pinIn);
}
analogWrite(pinOut, readSum / DEBOUNCE_READS);
if (DEBUG) {
switch (pinIn) {
case POT_R:
Serial.println('r');
break;
case POT_G:
Serial.println('g');
break;
case POT_B:
Serial.println('b');
break;
}
Serial.println(readSum / DEBOUNCE_READS);
delay(DEBUG_DELAY);
}
}