Back to Parent

#include "application.h"
//#include "spark_disable_wlan.h" // For faster local debugging only
#include "neopixel.h"

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 24
#define PIXEL_TYPE WS2812B

// Register the function of pixel library
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

// Assign integers to store score values
int MyTeam = 0;
int OtherGuys = 0;
int Total = MyTeam + OtherGuys;
int leadScore = 0;
int loseScore=0;


void setup()
{
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'

    Spark.subscribe("detroitredwingsevent", myHandler);
}

void loop()
{
  colorWipe();
}

// Function to wipe through ring with updated LED colors
void colorWipe()
{
  // Create ratio of MyTeam's score to Total as an integer that can be called
  double ratio = (MyTeam *1.0) / (Total * 1.0);
  double MyTeamRatio = 24.0 * ratio;
  int numTeam = (int)MyTeamRatio;

  for(uint16_t i=0; i<24; i++){
  // Color segment of ring corresponding to ratio of MyTeam's score
  // to Total score
    if( i < numTeam ){
      strip.setBrightness(32); // Scale the LED brightness to 12.5%
      strip.setPixelColor(i,strip.Color(255,0,0));
     }
     // Color segment of ring corresponding to ratio of OtherGuys's score
     // to Total score
    else{
      strip.setBrightness(32); // Scale the LED brightness to 12.5%
      strip.setPixelColor(i,strip.Color(255,255,255));
     }
    strip.show();
    delay(80); // how long to wait (ms) in between individual LEDs filling up
  }
}

// Analyzing string from detroitredwingsevent to determine score
void myHandler(const char *event, const char *data)
{
    if (strcmp (data,"Red") == true) {
      MyTeam = 1;
    }
    else {
      OtherGuys = 1;
    }
    String text = String(data);

    int spacePosition = text.indexOf( "-" );

    String leadScoreText = text.substring( spacePosition -1 );
    String loseScoreText = text.substring( spacePosition +1 );

    int leadScore = leadScoreText.toInt();
    int loseScore = loseScoreText.toInt();
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0