Trying to implement function pointers in my code so I can pass numbers thru the serial monitor and call functions in my code. Right now trying to modify the function pointer declaration in my setup method so that the functions will accept arguments. But getting this error
expected primary expression before 'c'
on this line
functionPtrs[0] = colorWipe(uint32_t c, uint8_t wait); //error here!!
Can anyone help?
#include <Adafruit_NeoPixel.h>
#define PIN 10
// Define constants and variables for Relay
const int out1 = 5; // define Arduino pin connected to relay 1
Adafruit_NeoPixel strip = Adafruit_NeoPixel(144, PIN, NEO_GRB + NEO_KHZ800);
void (*functionPtrs[5])(); //the array of function pointers
void setup() {
pinMode(out1, OUTPUT); // initialize the digital pin as an output
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Serial.begin(115200);
functionPtrs[0] = colorWipe(uint32_t c, uint8_t wait); //error here!!
functionPtrs[1] = rainbow;
functionPtrs[2] = theaterChase;
functionPtrs[3] = rainbowCycle;
functionPtrs[4] = theaterChaseRainbow;
}
unsigned long serialdata;
int inbyte;
void loop() {
Serial.print("loop and serialdata=="+serialdata);
}//end loop
long getSerial()
{
serialdata = 0;
while (inbyte != '/')
{
inbyte = Serial.read();
if (inbyte > 0 && inbyte != '/')
{
serialdata = serialdata * 10 + inbyte - '0';
Serial.println(serialdata);
}
}
return serialdata;
inbyte = 0;
}
void toggleRelay() {
setRelay(1, 1); // enable relay 1
Serial.print("Relay 1: Enabled ... ");
delay(1000); // wait for a second
setRelay(1, 0);
Serial.println("Disabled"); // disable relay 1
delay(1000);
}
// enable or disable a relay (1 to 4)
void setRelay(int relay, int value)
{
if(relay > 0 && relay < 5) digitalWrite((relay + 4), value);
}
void callFunction(int index) {
(*functionPtrs[index])(); //calls the function at the index of `index` in the array
}
// function1
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
Serial.print('calling colorWipe');
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
//function2
void rainbow(uint32_t c, uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
//function3
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint32_t c, uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
//function4
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//function5
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint32_t c, uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}