function not declared in this scope

First of all, I’d like to kindly ask that you be patient with an absolute beginner, while I do have some knowledge of programming, it is somewhat rusty and not really angled at this kind of thing. So while I have a decent idea on what I want to do in theory, actually getting that down in code is something of a struggle.

At the moment, I’m using this crossfader sample as the basis for my program, combining it with MQTT using the pubsubclient library. Upon recieving a new RGB value over MQTT in the form of 3 values, from 0-100 for R, G and B, it will update the custom colour array to the recieved values, called MQTTCol. After redefining that colour array, it then calls the crossfade subroutine, passing MQTTCol.

Upon trying to verify the code (in it’s experimental form), I get:

exit status 1
'crossfade' was not declared in this scope

Moving the bits around hasn’t helped, and as far as I can tell, the void callback should be fully defined by the time it is called from the callback void. I ask again to forgive me of my shoddy coding habits, I’ve been learning quite a lot about this through denial and error!

#include <PubSubClient.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <SPI.h>


//Network Config
// Set the MAC address
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x5E, 0x69 };
 
// Set fallback IP address if DHCP fails
IPAddress ip(192,168,1,121);

// Set the broker server IP
byte server[] = { 192,168,1,120 };

int MQTTR;
int MQTTG;
int MQTTB;


// Output
int redPin = 9;   // Red LED,   connected to digital pin 9
int grnPin = 10;  // Green LED, connected to digital pin 10
int bluPin = 11;  // Blue LED,  connected to digital pin 11

// Color arrays
int black[3]  = { 0, 0, 0 };
int white[3]  = { 100, 100, 100 };
int red[3]    = { 100, 0, 0 };
int green[3]  = { 0, 100, 0 };
int blue[3]   = { 0, 0, 100 };
int yellow[3] = { 40, 95, 0 };
int dimWhite[3] = { 30, 30, 30 };
int MQTTCol[3] = { 0, 0, 0,};
// etc.


// Set initial color
int redVal = black[0];
int grnVal = black[1]; 
int bluVal = black[2];

int wait = 10;      // 10ms internal crossFade delay; increase for slower fades
int hold = 0;       // Optional hold when a color is complete, before the next crossFade
int DEBUG = 1;      // DEBUG counter; if set to 1, will write values back via serial
int loopCount = 60; // How often should DEBUG report?
int repeat = 3;     // How many times should we loop before stopping? (0 for no stop)
int j = 0;          // Loop counter for repeat

// Initialize color variables
int prevR = redVal;
int prevG = grnVal;
int prevB = bluVal;

// Set up the LED outputs

int calculateStep(int prevValue, int endValue) {
  int step = endValue - prevValue; // What's the overall gap?
  if (step) {                      // If its non-zero, 
    step = 1020/step;              //   divide by 1020
  } 
  return step;
}

/* The next function is calculateVal. When the loop value, i,
*  reaches the step size appropriate for one of the
*  colors, it increases or decreases the value of that color by 1. 
*  (R, G, and B are each calculated separately.)
*/

int calculateVal(int step, int val, int i) {

  if ((step) && i % step == 0) { // If step is non-zero and its time to change a value,
    if (step > 0) {              //   increment the value if step is positive...
      val += 1;           
    } 
    else if (step < 0) {         //   ...or decrement it if step is negative
      val -= 1;
    } 
  }
  // Defensive driving: make sure val stays in the range 0-255
  if (val > 255) {
    val = 255;
  } 
  else if (val < 0) {
    val = 0;
  }
  return val;
}

/* crossFade() converts the percentage colors to a 
*  0-255 range, then loops 1020 times, checking to see if  
*  the value needs to be updated each time, then writing
*  the color values to the correct pins.
*/


void crossFade(int color[3]) {
  // Convert to 0-255
  int R = (color[0] * 255) / 100;
  int G = (color[1] * 255) / 100;
  int B = (color[2] * 255) / 100;

  int stepR = calculateStep(prevR, R);
  int stepG = calculateStep(prevG, G); 
  int stepB = calculateStep(prevB, B);

  for (int i = 0; i <= 1020; i++) {
    redVal = calculateVal(stepR, redVal, i);
    grnVal = calculateVal(stepG, grnVal, i);
    bluVal = calculateVal(stepB, bluVal, i);

    analogWrite(redPin, redVal);   // Write current values to LED pins
    analogWrite(grnPin, grnVal);      
    analogWrite(bluPin, bluVal); 

    delay(wait); // Pause for 'wait' milliseconds before resuming the loop

    if (DEBUG) { // If we want serial output, print it at the 
      if (i == 0 or i % loopCount == 0) { // beginning, and every loopCount times
        Serial.print("Loop/RGB: #");
        Serial.print(i);
        Serial.print(" | ");
        Serial.print(redVal);
        Serial.print(" / ");
        Serial.print(grnVal);
        Serial.print(" / ");  
        Serial.println(bluVal); 
      } 
      DEBUG += 1;
    }
  }
  // Update current values for next loop
  prevR = redVal; 
  prevG = grnVal; 
  prevB = bluVal;
  delay(hold); // Pause for optional 'wait' milliseconds before resuming the loop
}

void callback(char* topic, byte* payload, unsigned int length) {
  // check for messages on subscribed topics
  payload[length] = '\0';
  Serial.print("Topic: ");
  Serial.println(String(topic));
  


  // check topic to identify type of content
  if(String(topic) == "home/cabin/lights/RGB/brewing/com") {
    // convert payload to String
    String value = String((char*)payload);
    //value.trim();
    Serial.print (value);
    //Serial.flush();
    // split string at every "," and store in proper variable
    // convert final result to integer
    MQTTR = value.substring(0,value.indexOf(',')).toInt();
    MQTTG = value.substring(value.indexOf(',')+1,value.lastIndexOf(',')).toInt();
    MQTTB = value.substring(value.lastIndexOf(',')+1).toInt();

    // print obtained values for debugging
Serial.print("RED: ");
Serial.println(MQTTR);
//client.publish("status/arduino_LED", SoffitR);

Serial.print("GREEN: ");
Serial.println(MQTTG);
//client.publish("status/arduino_LED", SoffitG);

Serial.print("BLUE: ");
Serial.println(MQTTB);
//client.publish("status/arduino_LED/soffit/color/blue", int SoffitB);
//Serial.flush();

  MQTTCol[1] = MQTTR;
  MQTTCol[2] = MQTTG;
  MQTTCol[3] = MQTTB;
  crossfade(MQTTCol);
  
 
  
   while(Serial.available())
  Serial.read();
    
  }
}

EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);

void setup()
{

      // Open serial communications
  Serial.begin(9600);

  // Start with a hard-coded address:
    Serial.println("Assigning Static IP address:");
    Ethernet.begin(mac, ip);
  
     Serial.print("My address:");
  Serial.println(Ethernet.localIP());
  
  // Connect to Broker, give it arduino as the name
  if (client.connect("arduino")) {
    
    // Publish a message to the status topic
    client.publish("status/arduino","Arduino LED2 is now online");
    
    // Listen for messages on the control topic
    client.subscribe("home/cabin/lights/RGB/#");
  
  pinMode(redPin, OUTPUT);   // sets the pins as output
  pinMode(grnPin, OUTPUT);   
  pinMode(bluPin, OUTPUT); 

  if (DEBUG) {           // If we want to see values for debugging...
    Serial.begin(9600);  // ...set up the serial ouput 

      }
}


void loop()
{
  client.loop();
}

I’m certain this is something quite simple/stupid, but I am both of those things, it would seem!

Probably has to do with the fact that you didn't define "crossfade". You did define "crossFade", but that is not the same thing...

Regards,
Ray L.