/* Vorto Light A DIY Philips hue. By Mark de Reijer mailme@markdereijer.nl Like the Philips Hue, you can connect the VortoLight with IFTTT. Let IFTTT (or an other service, or youself) post sertain keywords on twitter. Thingspeak (and your sparkcore) scouts for those keywords and acts accordingly. The VortoLight uses WS2812B leds (also know as Neopixels from Adafruit). Based on 'MagicWord!' https://github.com/MrMdR/MagicWord Your sparkcore reads Twitter and execute an if/else statement when a matching word has been found! (acctually... ThingSpeak reads twitter and gives your spark core a kick to do something...) By Anouska de Graaf & Mark de Reijer Base by ls6 (cheerlights) https://github.com/ls6/spark-core-cheerlights/blob/master/spark-standalone/sparkCheerligts.cpp */ #include "application.h" //#include "spark_disable_wlan.h" // For faster local debugging only #include "neopixel/neopixel.h" // IMPORTANT: Set pixel COUNT, PIN and TYPE #define PIXEL_PIN D6 //witch pin do you use to control the leds? #define PIXEL_COUNT 7 //how many pixels does your lamp have? #define PIXEL_TYPE WS2812B //witch kind of leds do you use? Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE); TCPClient client; int ledPin = D7; //onboard LED pin String responseLine; String MagicTwitterWord; unsigned long nextPoll = 0; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); delay(2000); connectToTwitter(); pinMode(PIXEL_PIN, OUTPUT); strip.begin(); strip.setBrightness(250); strip.show(); // Initialize all pixels to 'off' } void connectToTwitter() { Serial.println("Connecting to Thingspeak..."); if (client.connect("api.thingspeak.com", 80)){ Serial.println("Connected to API..."); client.println("GET /channels/[INSERD_YOUR_OWN_CHANEL_ID]/field/1/last.txt HTTP/1.0"); client.println(); Serial.println("I'm connected to the channel! WooHoo!"); } else { Serial.println("Connection failed.... :( But do no need to cry! Just try again and know that you are beautiful :)"); } responseLine = ""; MagicTwitterWord = ""; } void readStatus() { Serial.println("Entering readStatus..."); while (client.available()) { Serial.println("Client is available!"); char ch = client.read(); MagicTwitterWord += ch; Serial.println("Building the magic word... "+MagicTwitterWord); }; client.stop(); Serial.println("Client stopped and ended the build."); Serial.println(); MagicTwitterWord.trim(); Serial.println("The magic Twitter word is: "+MagicTwitterWord); if (MagicTwitterWord == "off"){ Serial.println("VortoLight is now off :("); SetLedColor(strip.Color(0, 0, 0)); // black // switchLight(1); } // Notification colors else if (MagicTwitterWord == "red"){ Serial.println("VortoLight is now red!"); SetLedColor(strip.Color(255, 0, 0)); } else if (MagicTwitterWord == "blue"){ Serial.println("VortoLight is now blue!"); SetLedColor(strip.Color(0, 0, 255)); } else if (MagicTwitterWord == "green"){ Serial.println("VortoLight is now green!"); SetLedColor(strip.Color(0, 255, 0)); } else if (MagicTwitterWord == "purple"){ SetLedColor(strip.Color(250, 0, 250)); } else if (MagicTwitterWord == "pink"){ SetLedColor(strip.Color(255, 0, 255)); } // Lighting modes else if (MagicTwitterWord == "cozy"){ SetLedColor(strip.Color(255, 105, 0)); } else if (MagicTwitterWord == "study"){ SetLedColor(strip.Color(250, 165, 45)); } else if (MagicTwitterWord == "reading"){ SetLedColor(strip.Color(252, 135, 20)); } else if (MagicTwitterWord == "romantic"){ SetLedColor(strip.Color(255, 75, 0)); } else if (MagicTwitterWord == "industrial"){ SetLedColor(strip.Color(255, 255, 255)); } else { Serial.println("Didn't find a matching magic word."); //Didn't find the status Serial.println("The (not so) magic word I found was: "+MagicTwitterWord); Serial.println("number of symbols: "+MagicTwitterWord.length()); }; } void switchLight (int CaseNumber) { switch (CaseNumber) { case 1: // your code break; case 2: // your code break; default: digitalWrite(ledPin, LOW); }; } void SetLedColor(uint32_t c) { for(uint16_t i=0; i 0) { char cmd = Serial.read(); Serial.print("got: "); Serial.println(cmd); switchLight(cmd); }; }