/* * ----------------------- * Chroma - light in a box. * ----------------------- * Code by PerfectPixel, 2016. * Made with code snippets from Adafruit's Neopixel library and Bluetuino Examples * ----------------------- * PerfectPixel - http://www.instructables.com/member/perfectpixel * Adafruit - http://www.adafruit.com * Bluetuino - http://blog.bluetuino.com * ----------------------- */ #include #include #define PIN 9 Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800); SoftwareSerial bluetooth(10, 11); // RX, TX int fadespeed = 2; int manual = false; int mRed = 0; int mGreen = 0; int mBlue = 0; uint32_t colour = strip.Color(0,0,0); String receivedBluetoothString = ""; void setup() { bluetooth.begin(9600); strip.begin(); strip.show(); } void loop() { while (bluetooth.available() > 0) { char receivedBluetoothChar = bluetooth.read(); receivedBluetoothString += receivedBluetoothChar; if (receivedBluetoothChar == '\n') { if (receivedBluetoothString.toInt() == 876) { //RED - color preset #1 colour = strip.Color(255,0,0); //change this to change the colour } else if(receivedBluetoothString.toInt() == 877) { //GREEN - color preset #2 colour = strip.Color(0,255,0); //change this to change the colour }else if(receivedBluetoothString.toInt() == 878) { //BLUE - color preset #3 colour = strip.Color(0,0,255); //change this to change the colour }else if(receivedBluetoothString.toInt() == 1) { //RAINBOW (full) rainbow(fadespeed); }else if(receivedBluetoothString.toInt() == 2) { //RAINBOW (individual) rainbowCycle(fadespeed); }else if (receivedBluetoothString.endsWith("Slider\n")) { //FADESPEED SLIDER fadespeed = receivedBluetoothString.toInt(); } else if(receivedBluetoothString.toInt() == 55) { //MANUAL COLOUR CONTROL if(manual == true){ manual = false; } else if (manual == false){ manual = true; } } if (receivedBluetoothString.endsWith("RedSlider\n")) { //update mRed value mRed = receivedBluetoothString.toInt(); } if (receivedBluetoothString.endsWith("GreenSlider\n")) { //update mRed value mGreen = receivedBluetoothString.toInt(); } if (receivedBluetoothString.endsWith("BlueSlider\n")) { //update mRed value mBlue = receivedBluetoothString.toInt(); } if(manual == true){ //overwrides colours if manual control is active. colorWipe(strip.Color(mRed, mGreen, mBlue), 1); } else { colorWipe(colour, 1); //if manual color is not activated } receivedBluetoothString = ""; } } } void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i