adafruit_support_bill wrote:What does it do?
Print out the parsed values to make sure you are parsing them correctly.
Code: Select all
/*******************************************************************************
* Function Name : tinkerSetColour
* Description : Sets the strip with the appropriate colour
* Input : Pin and value
* Output : None.
* Return : 1 on success and a negative number on failure
*******************************************************************************/
int Rstart = 0, Gstart = 0, Bstart = 0;
int Rnew = 0, Gnew = 0, Bnew = 0;
int tinkerSetColour(String command)
{
sprintf(rgbString, "Rstart %i, Gstart %i, Bstart %i", Rstart, Gstart, Bstart);
Spark.publish("rgb", rgbString);
sprintf(rgbString, "Rnew %i, Gnew %i, Bnew %i", Rnew, Gnew, Bnew);
Spark.publish("rgb", rgbString);
// Clear strip.
strip.show();
int commaIndex = command.indexOf(',');
int secondCommaIndex = command.indexOf(',', commaIndex+1);
int lastCommaIndex = command.lastIndexOf(',');
int red = command.substring(0, commaIndex).toInt();
int grn = command.substring(commaIndex+1, secondCommaIndex).toInt();
int blu = command.substring(lastCommaIndex+1).toInt();
int Rend = red, Gend = grn, Bend = blu;
sprintf(rgbString, "Rend %i, Gend %i, Bend %i", Rend, Gend, Bend);
Spark.publish("rgb", rgbString);
// Larger values of 'n' will give a smoother/slower transition.
int n = 200;
for (int i = 0; i < n; i++)
{
Rnew = Rstart + (Rend - Rstart) * i / n;
Gnew = Gstart + (Gend - Gstart) * i / n;
Bnew = Bstart + (Bend - Bstart) * i / n;
// Set pixel color here.
strip.setPixelColor(0, strip.Color(Rnew, Gnew, Bnew));
}
sprintf(rgbString, "Rnew %i, Gnew %i, Bnew %i", Rnew, Gnew, Bnew);
Spark.publish("rgb", rgbString);
Rstart = red, Gstart = grn, Bstart = blu;
sprintf(rgbString, "Rstart %i, Gstart %i, Bstart %i", Rstart, Gstart, Bstart);
Spark.publish("rgb", rgbString);
return 1;
}
Code: Select all
Rstart 0, Gstart 0, Bstart 0
Rnew 0, Gnew 0, Bnew 0
Rend 255, Gend 0, Bend 0
Rnew 253, Gnew 0, Bnew 0
Code: Select all
Rstart 255, Gstart 0, Bstart 0
Rnew 253, Gnew 0, Bnew 0
Rend 0, Gend 255, Bend 0
Rnew 2, Gnew 253, Bnew 0
Code: Select all
Rstart 0, Gstart 255, Bstart 0
Rnew 2, Gnew 253, Bnew 0
Rend 0, Gend 23, Bend 255
Rnew 0, Gnew 25, Bnew 253