Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN 6
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 10
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // for serial message complete
String update = "";
void setup() {
Serial.begin(9600);
pixels.begin(); // This initializes the NeoPixel library.
}
boolean firstRun = true;
void loop() {
if (firstRun){
pixels.setPixelColor(0, pixels.Color(0,150,0));
pixels.setPixelColor(1, pixels.Color(0,150,0));
pixels.setPixelColor(2, pixels.Color(0,150,0));
pixels.setPixelColor(3, pixels.Color(0,150,0));
pixels.setPixelColor(4, pixels.Color(0,150,0));
pixels.setPixelColor(5, pixels.Color(0,150,0));
pixels.setPixelColor(6, pixels.Color(0,150,0));
pixels.setPixelColor(7, pixels.Color(0,150,0));
pixels.setPixelColor(8, pixels.Color(0,150,0));
pixels.setPixelColor(9, pixels.Color(0,150,0));
pixels.show();
firstRun = false;
}
if (stringComplete) {
inputString.replace("\n","");
update = inputString;
int lengthOfUpdate = update.length();
int space = update.indexOf(' ');
String location = update.substring(0, space);
String locationStatus = update.substring(space + 1, lengthOfUpdate);
changeLEDState(location, locationStatus);
// clear the string:
inputString = "";
stringComplete = false;
}
delay(delayval); // Delay for a period of time (in milliseconds).
}
void changeLEDState(String location, String locationStatus){
int pixel = 0;
if (location == "northcalifornia") {
pixel = 0;
}
else if (location == "vinadelmar") {
pixel = 1;
}
else if (location == "johannesburg") {
pixel = 2;
}
else if (location == "milan") {
pixel = 3;
}
else if (location == "frankfurt") {
pixel = 4;
}
else if (location == "london") {
pixel = 5;
}
else if (location == "stockholm") {
pixel = 6;
}
else if (location == "moscow") {
pixel = 7;
}
else if (location == "toyko") {
pixel = 8;
}
else if (location == "sydney") {
pixel = 9;
}
if (locationStatus == "down") {
Serial.print("updating ");
Serial.print(location);
Serial.println(" to down");
pixels.setPixelColor(pixel, pixels.Color(150,0,0));
} else if (locationStatus == "up") {
Serial.print("updating ");
Serial.print(location);
Serial.println(" to up");
pixels.setPixelColor(pixel, pixels.Color(0,150,0));
} else if (locationStatus == "slow") {
Serial.print("updating ");
Serial.print(location);
Serial.println(" to slow");
pixels.setPixelColor(pixel, pixels.Color(255,140,0));
}
pixels.show();
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment