-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbluetooth DMX Pixel.ino
128 lines (118 loc) · 2.81 KB
/
bluetooth DMX Pixel.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
//PWM LED Brightness and Bluetooth Serial Link Demo
//By keuwlsoft: www.keuwl.com 23rd Aug 2015
#include "FastLED.h"
#define NUM_LEDS 400
#define DATA_PIN 9
#define CLOCK_PIN 5
CRGB leds[NUM_LEDS];
//int Red_LED_Pin = 9; // PWM Pin for Red LED
//int Green_LED_Pin = 10; // PWM Pin for Green LED
//int Blue_LED_Pin = 11; // PWM Pin for Blue LED
//Varibles to hold brightness values ranging from 0 (off) to 255 (fully on)
int Red_value=0;
int Green_value=0;
int Blue_value=0;
int Delay_value=0;
char BluetoothData; // the data received from bluetooth serial link
void setup() {
delay(2000);
//FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// Initialise LED pins as outputs
// pinMode(Red_LED_Pin, OUTPUT);
// pinMode(Green_LED_Pin, OUTPUT);
// pinMode(Blue_LED_Pin, OUTPUT);
//initialsie serial communication
Serial.begin(9600);
FastLED.show();
}
void loop() {
//Process any info coming from the bluetooth serial link
if (Serial.available()){
BluetoothData=Serial.read(); //Get next character from bluetooth
/*if(BluetoothData=='R') Red_value=Serial.parseInt(); //Read Red value
if(BluetoothData=='G') Green_value=Serial.parseInt(); //Read Green Value
if(BluetoothData=='B') Blue_value=Serial.parseInt(); //Read Blue Value
if(BluetoothData=='D') Delay_value=Serial.parseInt(); //Read Blue Value
*/
if(BluetoothData=='W')
{
Red_value=255;
Green_value=255;
Blue_value=255;
}
if(BluetoothData=='w')
{
Red_value=0;
Green_value=0;
Blue_value=0;
}
if(BluetoothData=='R')
{
Red_value=255;
}
if(BluetoothData=='r')
{
Red_value=0;
}
if(BluetoothData=='G')
{
Green_value=255;
}
if(BluetoothData=='g')
{
Green_value=0;
}
if(BluetoothData=='B')
{
Blue_value=255;
}
if(BluetoothData=='b')
{
Blue_value=0;
}
if(BluetoothData=='C')
{
Delay_value=200;
}
if(BluetoothData=='c')
{
Delay_value=0;
}
if(BluetoothData=='D')
{
Delay_value=150;
}
if(BluetoothData=='d')
{
Delay_value=0;
}
if(BluetoothData=='E')
{
Delay_value=100;
}
if(BluetoothData=='e')
{
Delay_value=0;
}
}
//update LED Brightness
//analogWrite(Red_LED_Pin, Red_value);
//analogWrite(Green_LED_Pin, Green_value);
//analogWrite(Blue_LED_Pin, Blue_value);
if(Delay_value>1)
{leds[0].r = 0;
leds[0].g = 0;
leds[0].b = 0;
for(int i=1;i<NUM_LEDS;i++)
{leds[i]= leds[0]; }
FastLED.show();
}
delay(Delay_value);
leds[0].r = Red_value;
leds[0].g = Green_value;
leds[0].b = Blue_value;
for(int i=1;i<NUM_LEDS;i++)
{leds[i]=leds[0]; }
FastLED.show();
}