-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino_code.ino
115 lines (103 loc) · 2.26 KB
/
arduino_code.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
/**
* Let's Robot LED bot controller code.
* This handles all serial inputs from the Raspberry Pi.
* Current hard coded signals to avoid:
* f, b, l, r, s, t, o, p
*
* Presently accepted signals:
* y red up
* h red down
* u green up
* j green down
* i blue up
* k blue down
* n all on
* m all off
* z test on
* x test off
*/
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
//String red = "red: ";
//String green = "green: ";
//String blue = "blue: ";
boolean debug = false;
int redVal = 0;
int greenVal = 0;
int blueVal = 0;
int brightnessStep = 25;
void setup() {
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(13, OUTPUT);
Serial.println("ready");
}
void loop() {
if (Serial.available()) {
char input = Serial.read();
if (debug) {
Serial.print("found command: ");
Serial.println(input);
}
switch (input) {
case 'y':
redVal += brightnessStep;
if (redVal > 255) { redVal = 255; }
break;
case 'h':
redVal -= brightnessStep;
if (redVal < 0) { redVal = 0; }
break;
case 'u':
greenVal += brightnessStep;
if (greenVal > 255) { greenVal = 255; }
break;
case 'j':
greenVal -= brightnessStep;
if (greenVal < 0) { greenVal = 0; }
break;
case 'i':
blueVal += brightnessStep;
if (blueVal > 255) { blueVal = 255; }
break;
case 'k':
blueVal -= brightnessStep;
if (blueVal < 0) { blueVal = 0; }
break;
case 'n':
redVal = 255;
greenVal = 255;
blueVal = 255;
break;
case 'm':
redVal = 0;
greenVal = 0;
blueVal = 0;
break;
case 'z':
digitalWrite(13, HIGH);
break;
case 'x':
digitalWrite(13, LOW);
break;
case 'd':
debug = !debug;
break;
default:
break;
}
if (debug) {
Serial.print(redVal);
Serial.print('\t');
Serial.print(greenVal);
Serial.print('\t');
Serial.println(blueVal);
}
analogWrite(redPin, redVal);
analogWrite(greenPin, greenVal);
analogWrite(bluePin, blueVal);
}
}