'requestEvent' was not declared in this scope

Hi all!

I am trying to do an I2C from Mega to UNO and I am trying to look for a solution on this very simple problem however I am unable to find anything related to my query, so please bear with me. :smiley:

Anyway, I am receiving this error code 'requestEvent' was not declared in this scope

Here's my slave's code:

#include <Wire.h>

int DO = 2; //Pin for Digital Output - DO
int DA = A0; // Pin for Analog Output - AO
int threshold = 532; //Set minimum threshold for LED lit
int sensorvalue = 0;
int North[] = {2, 3, 4};
int West[] = {5, 6, 7};
int South[] = {8, 9, 10};
int East[] = {11, 12, 13};
int redDelay = 5000;
int yellowDelay = 2000;


 
void setup() {
  for (int i = 0; i < 3; i++) {
    pinMode(North[i], OUTPUT);
    pinMode(West[i], OUTPUT);
    pinMode(South[i], OUTPUT);
    pinMode(East[i], OUTPUT);
    Serial.begin(9600);
  Wire.begin(8);
  Wire.onRequest(requestEvent);

}
 
void loop() {
  sensorvalue = analogRead(DA);  //Read the analog value
  //Serial.print("Analog: ");
 // Serial.print(sensorvalue);  //Print the analog value
 // Serial.print("  ");
 // Serial.print("Digital: ");
 // Serial.println(digitalRead(DO));  //Print the digital value
 
  
}

  void requestEvent() {
    
    if (sensorvalue >= threshold) { //Compare analog value with threshold
    digitalWrite(North[1], HIGH);
    digitalWrite(West[1], HIGH);
    digitalWrite(South[1], HIGH);
    digitalWrite(East[1], HIGH);
    delay(yellowDelay);

    digitalWrite(North[0], HIGH);
    digitalWrite(West[0], HIGH);
    digitalWrite(South[0], HIGH);
    digitalWrite(East[0], HIGH);
    digitalWrite(North[1], LOW);
    digitalWrite(West[1], LOW);
    digitalWrite(South[1], LOW);
    digitalWrite(East[1], LOW);
    delay(redDelay);
    }
    
  }

I am pretty sure of my code and that I have declared it (as seen above). Just want to see what could be my possible error on this.

Thank you all! <3

Check the location of the } that ends the setup() function

Auto format in the IDE shows up the problem

Sugoiii. Thank you! My eyes are already tired, that's the error, I think.

Thanks alot!

Try adding a prototype of the function:

void requestEvent(void );

below your #include statement.

Did you try Auto format ?
Putting each { and } on its own line helps too

The requestEvent() is a interrupt function, you may not use delay() in there.
The requestEvent() is for sending data to the Master, but you don't send data. What do you use the requestEvent() for ?
The 'sensorValue' should be made 'volatile'.
To be sure that both bytes of 'sensorValue' belong to each other, you can turn off the interrupts temporarily in the loop().

Blackfin:
Try adding a prototype of the function:

void requestEvent(void );

below your #include statement.

Why? The prototype should have been automatically created by the IDE.

Is #include a statement or a pre-processing directive?

GolamMostafa:
Why? The prototype should have been automatically created by the IDE.

"Should have": In my experience the IDE does not have a 100% success rate.

Is #include a statement or a pre-processing directive?

yawn