Howdy everyone,
I’m having some issues with publishing one of my functions to the Spark Cloud. I’m getting the following error:
invalid conversion from 'void (*)(int)' to 'int (*)(String)' [-fpermissive]
This seems to be a fairly common error (seems like I’m passing arguments around incorrectly) but unfortunately I don’t know enough C to have any idea how to fix it. I’ve looked around at a few other posts but haven’t understood the answers:
I’ve published my code below, and it’s also on Github here. To be clear: I want to pass in a color through the Spark cloud to the threshold()
function — hopefully that’s actually possible.
/*
* This is a minimal example, see extra-examples.cpp for a version
* with more explantory documentation, example routines, how to
* hook up your pixels and all of the pixel types that are supported.
*
*/
#include "application.h"
#include "neopixel/neopixel.h"
SYSTEM_MODE(AUTOMATIC);
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
// Code that powers the neoring. Lights up when you get tweets! Built for the Particle: https://www.particle.io/
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(32, PIXEL_PIN);
uint32_t color = 30; // rgb value
void setup() {
pixels.begin();
threshold(color);
pixels.show();
// We are also going to declare a Spark.function so that we can turn the LED on and off from the cloud.
Spark.function("tweet", threshold);
// This is saying that when we ask the cloud for the function "threshold", it will employ the function threshold() from this app.
}
void loop() {
// need to have a loop function for some reason
}
// Loop animation
// Three for loops to make the animiation glow
void threshold(int color) {
int counter = 4;
int origColor = color;
for (counter; counter > 0; counter--) {
while(color > 0) {
// dim slowly
for(int i = 0; i < 16; i++) {
pixels.setPixelColor(i, pixels.Color(color, color, color));
}
pixels.show();
color -= 1;
delay(50);
}
// dim to nothing
for(int i = 0; i < 16; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
}
pixels.show();
delay(50);
// get brighter again
while (color < origColor) {
for(int i = 0; i < 16; i++) {
pixels.setPixelColor(i, pixels.Color(color, color, color));
}
pixels.show();
color += 1;
delay(50);
}
Serial.print(counter);
}
// Color displayed when nuthin's going on
for(int i = 0; i < 16; i++) {
pixels.setPixelColor(i, pixels.Color(5, 5, 5));
}
return 1;
}
Thank you so much!