Back to Parent

//Main.ino
//main for the LED core

//Array for LED
int LedPin[9] = {D0, D1, A0, A1, A2, A3, A4, A5, A6};
//number to count how many remoters
int countCore = 0;
//Array to count how many votes for each light
int ledLight[9] = {0,0,0,0,0,0,0,0,0};
int ledId;

int offPin = A7;

void setup()
{
  for(int i = 0; i < 9; i++)
  {
    pinMode(LedPin[i], OUTPUT);
    analogWrite(LedPin[i], 255);
  }

  pinMode(offPin, INPUT_PULLUP);

  Spark.subscribe("getTheCuteButton",handleLEDsetting);
  Spark.variable("1", &ledLight[0], INT);
  Spark.variable("2", &ledLight[1], INT);
  Spark.variable("led", &ledId, INT);
}

void loop()
{
  int read = digitalRead(offPin);
  if(read == LOW)
  {
    analogWrite(LedPin[0], 0);
  }
}

void handleLEDsetting(const char *event, const char *data)
{
  //everytime count 1
  countCore++;
  //get the ID of LED, set the vote++
  ledId = String(data).toInt();
  ledLight[ledId] ++;

  for(int i = 0; i < 9; i++)
  {
    int brightnessLED = 255/countCore*ledLight[ledId];
    analogWrite(LedPin[ledId], ledLight[ledId]);
  }
  //return 1;
}
Click to Expand

Content Rating

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

0