-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrgb.ino
73 lines (55 loc) · 1.28 KB
/
rgb.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
#include <SoftwareSerial.h>
SoftwareSerial BLU(0,1); // RX , TX
#define redPin 9
#define greenPin 10
#define bluePin 11
void setup()
{
//Serial setup
Serial.begin(9600);
Serial.println("-= HC-05 Bluetooth RGB LED =-");
BLU.begin(9600);
BLU.println("-= HC-05 Bluetooth RGB LED =-");
pinMode(4, OUTPUT);
digitalWrite(4,HIGH);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
setColor(255, 0, 0);
delay(500);
setColor(0, 255, 0);
delay(500);
setColor(0, 0, 255);
delay(500);
setColor(255, 255, 255);
}
void loop()
{
while (BLU.available() > 0)
{
int redInt = BLU.parseInt();
int greenInt = BLU.parseInt();
int blueInt = BLU.parseInt();
redInt = constrain(redInt, 0, 255);
greenInt = constrain(greenInt, 0, 255);
blueInt = constrain(blueInt, 0, 255);
if (BLU.available() > 0)
{
setColor(redInt, greenInt, blueInt);
Serial.print("Red: ");
Serial.print(redInt);
Serial.print(" Green: ");
Serial.print(greenInt);
Serial.print(" Blue: ");
Serial.print(blueInt);
Serial.println();
BLU.flush();
}
}
}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}