forked from arifmandal/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RGB_2.ino
43 lines (33 loc) · 873 Bytes
/
RGB_2.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
int redPin = 11;
int greenPin = 10;
int bluePin = 6;
int brightness = 255;
String colorChoice;
void setup() {
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
Serial.println("Please, input your color choice:(red, green,blue) ");
while (Serial.available() == 0) {}
colorChoice = Serial.readString();
if (colorChoice == "red") {
analogWrite(redPin, brightness);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
}
else if (colorChoice == "green") {
analogWrite(redPin, 0);
analogWrite(greenPin, brightness);
analogWrite(bluePin, 0);
}
else if (colorChoice == "blue") {
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, brightness);
} else {
Serial.println("Invalid choice: Please choose valid choice: ");
}
}