Skip to content

Commit

Permalink
Code cleanup, added tutorial link
Browse files Browse the repository at this point in the history
  • Loading branch information
iobridge committed Dec 19, 2014
1 parent 170a1be commit 3300c38
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions FastLED/Arduino_Ethernet.ino
@@ -1,4 +1,5 @@
/*
CheerLights!
CheerLights Channel --> Arduino Ethernet --> FastLED
Expand All @@ -12,8 +13,7 @@
* Arduino Ethernet (or Arduino + Ethernet Shield)
* Arduino 1.0+ IDE
* FastLED Library
https://github.com/FastLED/FastLED/releases
* FastLED Library - https://github.com/FastLED/FastLED/releases
Network Requirements:
* Ethernet port on Router
Expand All @@ -25,9 +25,12 @@
Additional Credits:
Example sketches from FastLED
ThingSpeak Tutorial:
http://community.thingspeak.com/tutorials/arduino/cheerlights-with-arduino-and-the-fastled-library/
To join the CheerLights project, visit http://www.cheerlights.com
*/
*/

#include <SPI.h>
#include <Ethernet.h>
Expand All @@ -46,17 +49,17 @@
CRGB leds[NUM_LEDS];

// Local Network Settings
byte mac[] = {
byte mac[] = {
0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; // Must be unique on local network

// ThingSpeak / CheerLights Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String thingSpeakChannel = "1417"; // Channel number of the CheerLights Channel
String thingSpeakField = "1"; // Field number of the CheerLights Colors
const int thingSpeakInterval = 6 * 1000; // Time interval in milliseconds to get data from ThingSpeak (number of seconds * 1000 = interval)
String thingSpeakField = "1"; // Field number of the CheerLights Colors
const int thingSpeakInterval = 10 * 1000; // Time interval in milliseconds to get data from ThingSpeak (number of seconds * 1000 = interval)

// Variable Setup
long lastConnectionTime = 0;
long lastConnectionTime = 0;
String lastCommand = "";
boolean lastConnected = false;
int failedCounter = 0;
Expand All @@ -79,24 +82,24 @@ void setup() {
FastLED.addLeds<NEOPIXEL,DATA_PIN>(leds, NUM_LEDS);
}

void loop() {
void loop() {

// Process CheerLights Commands
if(client.available() > 0)
{
delay(100);
delay(100);

String response;
char charIn;

do {
charIn = client.read(); // read a char from the buffer
response += charIn; // append that char to the string response
}
while (client.available() > 0);

// Send matching commands to the GE-35 Color Effect Lights
if (response.indexOf("white") > 0)
}
while (client.available() > 0);
// Send matching commands to LEDs
if (response == "white")
{
lastCommand = "white";

Expand All @@ -106,17 +109,17 @@ void loop() {
delay(30);
}
}
else if (response.indexOf("red") > 0)
{
lastCommand = "red";
else if (response == "red")
{
lastCommand = "red";

for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Red;
FastLED.show();
delay(30);
}
}
else if (response.indexOf("green") > 0)
else if (response == "green")
{
lastCommand = "green";

Expand All @@ -126,7 +129,7 @@ void loop() {
delay(30);
}
}
else if (response.indexOf("blue") > 0)
else if (response == "blue")
{
lastCommand = "blue";

Expand All @@ -136,7 +139,7 @@ void loop() {
delay(30);
}
}
else if (response.indexOf("cyan") > 0)
else if (response == "cyan")
{
lastCommand = "cyan";

Expand All @@ -146,7 +149,7 @@ void loop() {
delay(30);
}
}
else if (response.indexOf("magenta") > 0)
else if (response == "magenta")
{
lastCommand = "magenta";

Expand All @@ -156,7 +159,7 @@ void loop() {
delay(30);
}
}
else if (response.indexOf("yellow") > 0)
else if (response == "yellow")
{
lastCommand = "yellow";

Expand All @@ -166,7 +169,7 @@ void loop() {
delay(30);
}
}
else if (response.indexOf("purple") > 0)
else if (response == "purple")
{
lastCommand = "purple";

Expand All @@ -176,7 +179,7 @@ void loop() {
delay(30);
}
}
else if (response.indexOf("orange") > 0)
else if (response == "orange")
{
lastCommand = "orange";

Expand All @@ -186,7 +189,7 @@ void loop() {
delay(30);
}
}
else if (response.indexOf("warmwhite") > 0)
else if (response == "warmwhite")
{
lastCommand = "warmwhite";

Expand All @@ -196,7 +199,7 @@ void loop() {
delay(30);
}
}
else if (response.indexOf("oldlace") > 0)
else if (response == "oldlace")
{
lastCommand = "oldlace";

Expand All @@ -206,7 +209,7 @@ void loop() {
delay(30);
}
}
else if (response.indexOf("pink") > 0)
else if (response == "pink")
{
lastCommand = "pink";

Expand All @@ -225,7 +228,7 @@ void loop() {
delay(200);
Serial.println("CheerLight Command Received: "+lastCommand);
Serial.println();
delay(200);
delay(200);
}

// Disconnect from ThingSpeak
Expand Down Expand Up @@ -261,7 +264,7 @@ void subscribeToThingSpeak(String tsChannel, String tsField)

failedCounter = 0;

client.println("GET /channels/"+tsChannel+"/field/"+tsField+"/last.txt HTTP/1.0");
client.println("GET /channels/"+tsChannel+"/field/"+tsField+"/last.txt");
client.println();

lastConnectionTime = millis();
Expand All @@ -270,10 +273,10 @@ void subscribeToThingSpeak(String tsChannel, String tsField)
{
failedCounter++;

Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
Serial.println();

lastConnectionTime = millis();
lastConnectionTime = millis();
}
}

Expand All @@ -283,7 +286,7 @@ void startEthernet()
client.stop();

Serial.println("Connecting Arduino to network...");
Serial.println();
Serial.println();

delay(1000);

Expand Down

0 comments on commit 3300c38

Please sign in to comment.