Not declared in this scope -problem

I am havin an issue with a very compley saketch.
Its a program for a automatic pet feeding system.

im having following kind of errors:

C:\Users\Manuel\Documents\Arduino\Nokia5110Menu2_copy_20221019092448\Nokia5110Menu2_copy_20221019092448.ino: In function 'void loop()':
C:\Users\Manuel\Documents\Arduino\Nokia5110Menu2_copy_20221019092448\Nokia5110Menu2_copy_20221019092448.ino:59:7: error: 'erogate' was not declared in this scope
       erogate();
       ^~~~~~~

but erogate for example can be found below in the code as void erogate() {.....}

i checked all curved brackets and can't find errors of that kind.

here the link to the full .ino file:
code in the post below

Please show your full sketch.
Nothing can be said without the code

code can be downloaded on the link ... its big..

Do not force the others downloading stuff from external link.
Please insert the code in the forum with code tags.

Please post the BIG code in code tags.

I bet the OP defined the function erogate() inside loop().

ok

#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <Servo.h>



Adafruit_PCD8544 display = Adafruit_PCD8544( 5, 4, 3);
Servo myservo;

boolean backlight = true;
int Contrast=60;

int upButton = 2;
int downButton = 0;
int selectButton = 8;
int petButton = 12;
int menu = 1;
int feedingMenu =1;
int contrastPage =0;
int intervalPage =0;
int portionPage =0;
int autoFeedingPage =0;
int portionSize =500;
int autoFeeding = 0;
int feedingInt = 2;
unsigned long feedingIntTime = 0;
unsigned long petPressDelay = 0;
unsigned long currentmillisPet=0;
unsigned long startOffset = 0;
unsigned long feedingStartTime = 0;







void setup() {
  display.begin();      
  display.setContrast(Contrast); //Set Contrast to 50
  display.clearDisplay(); 
  display.display();  

  
  pinMode(upButton, INPUT_PULLUP);
  pinMode(downButton, INPUT_PULLUP);
  pinMode(selectButton, INPUT_PULLUP);
  pinMode(7,OUTPUT);
  pinMode(petButton, INPUT_PULLUP);
  digitalWrite(7,LOW);
  updateMenu();

}

void loop() {

   if ((autoFeeding == 1) && ((feedingIntTime+startOffset-feedingStartTime)<=1000)){
    erogate();
   }    
   if (!digitalRead(petButton)){
      if (millis()-petPressDelay >= 5000) {
      petPress();    
      delay(100);
      while (!digitalRead(petButton)); 
      }  
      else {
        updateMenu();
      } 
  }
  if (!digitalRead(downButton)){
    if (contrastPage==1){
      Contrast++;
      display.setContrast(Contrast);
      updateMenu();
      delay(100);
      while (!digitalRead(downButton));
    }
    else if (autoFeedingPage==1){
      feedingMenu++;
      updateFeeding();
      delay(100);
      while (!digitalRead(downButton));
    }
    else if (intervalPage==1){
      feedingInt++;
      if (feedingInt ==3){
        feedingInt =2;        
      }
      updateMenu();
      delay(100);
      while (!digitalRead(downButton));
    }
    else if (portionPage==1){
      portionSize++;
      updateMenu();
      delay(50);      
    }    
    else {
    menu++;
    updateMenu();
    delay(100);
    while (!digitalRead(downButton));
    }
  }
  if (!digitalRead(upButton)){
     if (contrastPage==1){
     Contrast--;
     display.setContrast(Contrast);
     updateMenu();
     delay(100);
     while (!digitalRead(upButton));
     }
    else if (autoFeedingPage==1){
      feedingMenu--;
      updateFeeding();
      delay(100);
      while (!digitalRead(downButton));
    }      
     else if (intervalPage==1){
      feedingInt--; 
      if (feedingInt == 0){
        feedingInt = 1;        
      }
      updateMenu();
      delay(100);
      while (!digitalRead(upButton));
    }
    else if (portionPage==1){
      portionSize--;
      updateMenu();
      delay(50);     
    }   
    else {
    menu--;
    updateMenu();
    delay(100);
    while(!digitalRead(upButton));
    }
  }
  if (!digitalRead(selectButton)){
     if (contrastPage==1){
      contrastPage=0;
      menu= 6;    
      updateMenu();
      delay(100);
      while (!digitalRead(selectButton));
     }
     else if (intervalPage==1){
      intervalPage=0;
      menu= 4;    
      updateMenu();
      delay(100);
      while (!digitalRead(selectButton));
     }  
     else if (portionPage==1){
      portionPage = 0;
      menu = 5;      
      updateMenu();
      delay(100);
      while (!digitalRead(selectButton));
    }   
    else if (autoFeedingPage==1){
    executeFeedingAction();
    autoFeedingPage = 0;    
    updateMenu();
    delay(100);
    while (!digitalRead(selectButton));
    }       
    else {
    executeAction();
    updateMenu();
    delay(100);
    while (!digitalRead(selectButton));
    }    
  }
}

void updateMenu() {
  if (autoFeedingPage == 1){
    udateFeeding();
  }
  switch (menu) {
    case 0:
      menu = 1;
      break;
    case 1:
      display.setTextSize(1);
      display.clearDisplay();
      display.setTextColor(BLACK, WHITE);
      display.setCursor(15, 0);
      if (autoFeeding == 1){
        display.print("MAIN MENU A");        
      }
      else{
      display.print("MAIN MENU");          
      }      
      display.drawFastHLine(0,10,83,BLACK);
      display.setCursor(0, 15);
      display.setTextColor(WHITE, BLACK);
      display.print(" Erogate Food");
      display.setCursor(0, 25);
      display.setTextColor(BLACK, WHITE); 
      display.print(" Light ON/OFF");   
      display.setCursor(0, 35);
      display.setTextColor(BLACK, WHITE); 
      display.print(" Auto Feeding");   
      display.display();
      break;
    case 2:
      display.setTextSize(1);
      display.clearDisplay();
      display.setTextColor(BLACK, WHITE);
      display.setCursor(15, 0);
      if (autoFeeding == 1){
        display.print("MAIN MENU A");        
      }
      else{
      display.print("MAIN MENU");          
      }      
      display.drawFastHLine(0,10,83,BLACK);
      display.setCursor(0, 15);
      display.setTextColor(BLACK, WHITE);
      display.print(" Erogate Food");
      display.setCursor(0, 25);
      display.setTextColor(WHITE, BLACK); 
      display.print(" Light ON/OFF");   
      display.setCursor(0, 35);
      display.setTextColor(BLACK, WHITE); 
      display.print(" Auto Feeding");   
      display.display();
      break;
    case 3:
      display.setTextSize(1);
      display.clearDisplay();
      display.setTextColor(BLACK, WHITE);
      display.setCursor(15, 0);
      if (autoFeeding == 1){
        display.print("MAIN MENU A");        
      }
      else{
      display.print("MAIN MENU");          
      }      
      display.drawFastHLine(0,10,83,BLACK);
      display.setCursor(0, 15);
      display.setTextColor(BLACK, WHITE);
      display.print(" Erogate Food");
      display.setCursor(0, 25);
      display.setTextColor(BLACK, WHITE); 
      display.print(" Light ON/OFF");   
      display.setCursor(0, 35);
      display.setTextColor(WHITE, BLACK); 
      display.print(" Auto Feeding");  
      display.display(); 
      break;
    case 4:
      display.setTextSize(1);
      display.clearDisplay();
      display.setTextColor(BLACK, WHITE);
      display.setCursor(15, 0);
      if (autoFeeding == 1){
        display.print("MAIN MENU A");        
      }
      else{
      display.print("MAIN MENU");          
      }      
      display.drawFastHLine(0,10,83,BLACK);
      display.setCursor(0, 15);
      display.setTextColor(WHITE, BLACK);
      display.print(" Feeding Int.");
      display.setCursor(0, 25);
      display.setTextColor(BLACK, WHITE); 
      display.print(" Portion Size");   
      display.setCursor(0, 35);
      display.setTextColor(BLACK, WHITE); 
      display.print(" Contrast");   
      display.display();
      break;   
    case 5:
      display.setTextSize(1);
      display.clearDisplay();
      display.setTextColor(BLACK, WHITE);
      display.setCursor(15, 0);
      if (autoFeeding == 1){
        display.print("MAIN MENU A");        
      }
      else{
      display.print("MAIN MENU");          
      }      
      display.drawFastHLine(0,10,83,BLACK);
      display.setCursor(0, 15);
      display.setTextColor(BLACK, WHITE);
      display.print(" Feeding Int.");
      display.setCursor(0, 25);
      display.setTextColor(WHITE, BLACK); 
      display.print(" Portion Size");   
      display.setCursor(0, 35);
      display.setTextColor(BLACK, WHITE); 
      display.print(" Contrast"); 
      display.display();  
      break;   
    case 6:
      display.setTextSize(1);
      display.clearDisplay();
      display.setTextColor(BLACK, WHITE);
      display.setCursor(15, 0);
      if (autoFeeding == 1){
        display.print("MAIN MENU A");        
      }
      else{
      display.print("MAIN MENU");          
      }      
      display.drawFastHLine(0,10,83,BLACK);
      display.setCursor(0, 15);
      display.setTextColor(BLACK, WHITE);
      display.print(" Feeding Int.");
      display.setCursor(0, 25);
      display.setTextColor(BLACK, WHITE); 
      display.print(" Portion Size");   
      display.setCursor(0, 35);
      display.setTextColor(WHITE, BLACK); 
      display.print(" Contrast");  
      display.display(); 
      break;   
    case 7:
      menu = 6;
      break;
    case 8:
      contrastPage = 1;
     display.setTextSize(1);
     display.clearDisplay();
     display.setTextColor(BLACK, WHITE);
     display.setCursor(15, 0);
     display.print("Contrast");
     display.drawFastHLine(0,10,83,BLACK);
     display.setCursor(5, 15);
     display.print("Value");
     display.setTextSize(2);
     display.setCursor(5, 25);
     display.print(Contrast);
     display.setTextSize(2);
     display.display();
      break;   
    case 9:
      intervalPage = 1;
     display.setTextSize(1);
     display.clearDisplay();
     display.setTextColor(BLACK, WHITE);
     display.setCursor(10, 0);
     display.print("Set Interval");
     display.drawFastHLine(0,10,83,BLACK);
     display.setCursor(5, 15);
     display.print("feed every");
     display.setTextSize(2);
     display.setCursor(5, 25);
     if (feedingInt == 1){
     display.print("12h");
     }
     if (feedingInt == 2){
     display.print("24h");
     }     
     display.setTextSize(2);
     display.display();
      break;   
    case 10:
      portionPage = 1;
     display.setTextSize(1);
     display.clearDisplay();
     display.setTextColor(BLACK, WHITE);
     display.setCursor(15, 0);
     display.print("Portion");
     display.drawFastHLine(0,10,83,BLACK);
     display.setCursor(5, 15);
     display.print("Daily:");
     display.setTextSize(2);
     display.setCursor(5, 25);
     display.print(portionSize);
     display.setTextSize(2);
     display.display();
      break;   
  }
}

void executeAction() {
  switch (menu) {
    case 1:
      action1();
      break;
    case 2:
      action2();
      break;
    case 3:
      action3();
      break;
    case 4:
      action4();
      break;
    case 5:
      action5();
      break;
    case 6:
      action6();
      break;
  }
}

void action1() {
  display.clearDisplay();
  display.setCursor(0, 15);
  display.print("Enjoy!");
  display.display();
  myservo.attach(9);
  myservo.write(0);
  delay(portionSize);
  myservo.write(90);
  delay(100);
  myservo.detach();
}
void action2() {
if (backlight) 
      {
        backlight = false;
        digitalWrite(7,HIGH);
        }
      else 
      {
        backlight = true; 
        digitalWrite(7,LOW);
       }
}
void action3() {
  autoFeedingPage = 1;
}
void action4() {
menu = 9;
}
void action5() {
  menu = 10;
}
void action6() {
  menu = 8;
}
void petPress(){
  display.clearDisplay();
  display.setCursor(0, 15);
  display.print("Enjoy!");
  display.display();
  myservo.attach(9);
  myservo.write(0);
  delay(120);
  myservo.write(90);
  delay(100);
  myservo.detach();
  petPressDelay=millis();
  updateMenu();  
}

void udateFeeding(){
switch (feedingMenu) {
    case 0:
      feedingMenu = 1;
      break;
    case 1:
      display.setTextSize(1);
      display.clearDisplay();
      display.setTextColor(BLACK, WHITE);
      display.setCursor(0, 0);
      display.print("STARTING IN");        
      display.drawFastHLine(0,10,83,BLACK);
      display.setCursor(0, 15);
      display.setTextColor(WHITE, BLACK);
      display.print(" Deactivate");
      display.setCursor(0, 25);
      display.setTextColor(BLACK, WHITE); 
      display.print(" Immediately");   
      display.setCursor(0, 35);
      display.setTextColor(BLACK, WHITE); 
      display.print(" 1 Hour");   
      display.display();
      break;
    case 2:
      display.setTextSize(1);
      display.clearDisplay();
      display.setTextColor(BLACK, WHITE);
      display.setCursor(0, 0);
      display.print("STARTING IN");        
      display.drawFastHLine(0,10,83,BLACK);
      display.setCursor(0, 15);
      display.setTextColor(BLACK, WHITE);
      display.print(" Deactivate");
      display.setCursor(0, 25);
      display.setTextColor(WHITE, BLACK); 
      display.print(" Immediately");   
      display.setCursor(0, 35);
      display.setTextColor(BLACK, WHITE); 
      display.print(" 1 Hour");   
      display.display();
      break;
    case 3:
      display.setTextSize(1);
      display.clearDisplay();
      display.setTextColor(BLACK, WHITE);
      display.setCursor(0, 0);
      display.print("STARTING IN");        
      display.drawFastHLine(0,10,83,BLACK);
      display.setCursor(0, 15);
      display.setTextColor(BLACK, WHITE);
      display.print(" Deactivate");
      display.setCursor(0, 25);
      display.setTextColor(BLACK, WHITE); 
      display.print(" Immediately");   
      display.setCursor(0, 35);
      display.setTextColor(WHITE, BLACK); 
      display.print(" 1 Hour");   
      display.display();
      break;
    case 4:
      display.setTextSize(1);
      display.clearDisplay();
      display.setTextColor(BLACK, WHITE);
      display.setCursor(0, 0);
      display.print("STARTING IN");        
      display.drawFastHLine(0,10,83,BLACK);
      display.setCursor(0, 15);
      display.setTextColor(WHITE, BLACK);
      display.print(" 2 Hours");
      break;
  case 5:
     feedingMenu = 4;
     break;     
}

void executeFeedingAction() {
  switch (feedingMenu) {
    case 1:
      feedingaAction1();
      break;
    case 2:
      feedingaAction2();
      break;
    case 3:
      feedingaAction3();
      break;
    case 4:
      feedingaAction4();
      break;
  }
}


void feedingAction1() {
  display.clearDisplay();
  display.setTextColor(BLACK, WHITE);  
   autoFeeding = 0;
   display.setCursor(0, 15);      
   display.print("Automatic feeding"); 
   display.setCursor(0, 25);
   display.print(">DEACTIVATE<");
   display.display();
   autoFeedingPage = 1;
   delay(2000);
}
void feedingAction2() {
  display.clearDisplay();
  display.setTextColor(BLACK, WHITE);  
   autoFeeding = 1;
   feedingStartTime = millis();
   display.setCursor(0, 15);      
   display.print("Automatic feeding"); 
   display.setCursor(0, 25);
   display.print(">ACTIVATE<");
   display.setCursor(0, 25);
   display.print("Starting Now");
   display.display();
   startOffset = 0;
   autoFeedingPage = 0;
   delay(2000);
}
void feedingAction3() {
   display.clearDisplay();
   display.setTextColor(BLACK, WHITE);  
   autoFeeding = 1;
   feedingStartTime = millis();
   display.setCursor(0, 15);      
   display.print("Automatic feeding"); 
   display.setCursor(0, 25);
   display.print(">ACTIVATE<");
   display.setCursor(0, 25);
   display.print("Starting in 1h");
   display.display();
   startOffset = 3600000;   
   autoFeedingPage = 0;
   delay(2000);
}
void feedingAction4() {
   display.clearDisplay();
   display.setTextColor(BLACK, WHITE);  
   autoFeeding = 1;
   feedingStart = 1;
   display.setCursor(0, 15);      
   display.print("Automatic feeding"); 
   display.setCursor(0, 25);
   display.print(">ACTIVATE<");
   display.setCursor(0, 25);
   display.print("Starting in 2h");
   display.display();
   startOffset = 7200000;   
   autoFeedingPage = 0;
   delay(2000);
}
void erogate() {
  if (feedingInt == 1){
    display.clearDisplay();
    display.setCursor(0, 15);
    display.print("Enjoy!");
    display.display();
    myservo.attach(9);
    myservo.write(0);
    delay(portionSize/2);
    myservo.write(90);
    delay(100);
    myservo.detach();
  }          
  else if (feedingInt == 2){
    display.clearDisplay();
    display.setCursor(0, 15);
    display.print("Enjoy!");
    display.display();
    myservo.attach(9);
    myservo.write(0);
    delay(portionSize);
    myservo.write(90);
    delay(100);
    myservo.detach();
  }  
  startOffset = 0;
  udateMenu();   
}
1 Like

Do you know what scope is talking about?

See if you can read about variable scope - that will help you help yourself.

op look at void udateFeeding() { where is the closing }?

Use Auto format, OP.

Issue solved quickly with the posted code. Thanks.

And that's not BIG code.

... next...
The function name is

but it called as

Your code contains a lot of errors...

1 Like

Your sketch contains a number of syntax errors.

To start with in the editor enter CNTL-T - this will indent the code, and if you scroll down you will see missing }'s. This will solve the original problem.

Beyond that there are also a number of spelling mistakes as noted above.... just fix one at a time.

1 Like

thank you very much :slight_smile:

i know, all solved! thx

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.