/*
* LED / RGB Strip Control via Bluetooth HC-06
* by Masum Ahmed (Ma786), ma786@kent.ac.uk
*
*/
#include
#define PIN 10 //RGB strip
#define N_LEDS 8 //number of led
#define led 11 // test led
int x = N_LEDS - 1;
long state;
long brightness;
int rgbR = 5;
int rgbG = 5;
int rgbB = 5;
boolean powerON = false;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
while (Serial.available()) {
state = Serial.parseInt();
//Serial.println(state);
setValues();
RGBstrip();
ledControl();
}
}
void setValues() {
switch (state) {
case 1:
powerON = true;
break;
case 2:
powerON = false;
break;
case 3: //brightness
brightness = Serial.read();
//Serial.println(brightness);
break;
case 4: //green
rgbG = Serial.read();
//Serial.println(rgbG);
break;
case 5: //red
rgbR = Serial.read();
//Serial.println(rgbR);
break;
case 6: //blue
rgbB = Serial.read();
// Serial.println(rgbB);
break;
default:
break;
}
}
void RGBstrip () {
strip.setBrightness(brightness);
for (int i = 0; i < x; i++) {
strip.setPixelColor(i, rgbR, rgbG, rgbB); //rgb value red green blue
}
strip.show();
}
void ledControl() {
if (powerON) {
digitalWrite(led, HIGH);
}
if (!powerON) {
digitalWrite(led, LOW);
}
}