Two actions at the same - not exactly kind of

Hi guys :slight_smile: first, I am sorry about my english.

I am trying to do kind of two actions at the same time.
I did void X and in the void I did for loop and its happend 7 times.
In each time the arduino turn the servo 180 degrees and back and then wait one day.
I want to do that in that day delay I can command him for other things.
Can I do it?

Thx for trying :slight_smile:

No problem at all, except you have to write new code :wink:

You need to learn 'state machine'. It is kind of new way of thinking if you are used to delays.
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

Sure you can do that. Basically you want your void function to be triggered once a day.

Do you have a real time clock attached to your set up or do you only rely on internal functions like millis()?

If you have a RTC, it's very easy look at a RTC library and how to trigger events on a daily basis

If you don't then you'll need to keep track of time yourself in your sketch and it's a bit more difficult as millis() (Returns the number of milliseconds since the Arduino board began running the current program) will overflow (go back to zero), after approximately 50 days.

Gabriel_swe:
No problem at all, except you have to write new code :wink:

You need to learn 'state machine'. It is kind of new way of thinking if you are used to delays.
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

It is since but its not working for me here my half code

void feedingMikey()
{
for(int i=0;i<=7;i++)
{
if(millis() >= goTime) functionGo();
goTime = millis() + nextTime;
}
}

void functionGo(){
//do what we want
delay(1000);
Mikeyservo.write(185);//Switch the servo to feed Mikey
delay(1000);//Wait 1 seconed
Mikeyservo.write(0);//Rest the servo
// set when to do it again
}

Your use of millis is flawed, it uses future time stamps. That will give you a problem with overflows. You didn't post all your code so we can't see what data type "goTime" is. It must be unsigned long. Look at the Blink without Delay sketch, you can easily modify it to blink once a day.

aarg:
Your use of millis is flawed, it uses future time stamps. That will give you a problem with overflows. You didn't post all your code so we can't see what data type "goTime" is. It must be unsigned long. Look at the Blink without Delay sketch, you can easily modify it to blink once a day.

int nextTime = 8460000;
long int goTime;
my code is very long and it will for you like a mess but do you want i post him?

unsigned int only holds 0 to 65535.
Use unsigned long instead.

CrossRoads:
unsigned int only holds 0 to 65535.
Use unsigned long instead.

You are right but I wasnt get to this point yet
I have this:

void feedingMikey()
{
for(int i=0;i<=7;i++)
{
if(millis() >= goTime) functionGo();
Serial.println("happened");
}
}

void functionGo(){
//do what we want
delay(1000);
Mikeyservo.write(185);//Switch the servo to feed Mikey
delay(1000);//Wait 1 seconed
Mikeyservo.write(0);//Rest the servo
goTime = millis() + nextTime;// set when to do it again
}

Now what is the problem thats not w8 bettwen every loop of for i tried put this line in the for:
goTime = millis() + nextTime;
but its not work you have ideas?

@ ido8780:

I feel that you are using this as a feeding device,

first of if you could use an RTC would great for you.

you could also use Time library and TimeAlarm library to work out the Timing for each day.

just in case you want to still use millis();

the way I would approach this is by understanding blink without delay example.

/* Blink without Delay

 Turns on and off a light emitting diode (LED) connected to a digital
 pin, without using the delay() function.  This means that other code
 can run at the same time without being interrupted by the LED code.

 The circuit:
 * LED attached from pin 13 to ground.
 * Note: on most Arduinos, there is already an LED on the board
 that's attached to pin 13, so no hardware is needed for this example.

 created 2005
 by David A. Mellis
 modified 8 Feb 2010
 by Paul Stoffregen
 modified 11 Nov 2013
 by Scott Fitzgerald


 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
 */

// constants won't change. Used here to set a pin number :
const int ledPin =  13;      // the number of the LED pin

// Variables will change :
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

now what happen if I just have this ?

unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  Serial.begin ( 9600 );
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) 
  {
   previousMillis = currentMillis;
   Serial.print ( interval / 1000 );
   Serial.println ( " second had passed since last update" );
    }
}

amazing what possibility that we could now do;

what if we change the Serial.print into a function?

unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  Serial.begin ( 9600 );
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) 
  {
   previousMillis = currentMillis;
   doSomething ();
    }
}

void doSomething ()
{
  Serial.print ( interval / 1000 );
  Serial.println ( " second had passed since last update" );
}

now the function could be doing anything you like, This is just an example...

now how about we add some definition on top of the code, thing that define whats a day, hour, minute, second is.

#define second(x) x*1000
#define minute(x) x*60000
#define hour(x) x*3600000
#define day(x) x*86400000

with this definition on top of my code, I think I could do something simple like

#define second(x) x*1000
#define minute(x) x*60000
#define hour(x) x*3600000
#define day(x) x*86400000

unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = second(1);           // interval at which to blink

void setup() {
  Serial.begin ( 9600 );
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) 
  {
   previousMillis = currentMillis;
   doSomething ();
    }
}

void doSomething ()
{
  Serial.print ( interval / 1000 );
  Serial.println ( " second had passed since last update" );
}

I think you'll see the functionality you wanted with the last example

lets make it more interesting?

#define second(x) x*1000
#define minute(x) x*60000
#define hour(x) x*3600000
#define day(x) x*86400000

unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = second(1);           // interval at which to blink

void setup() {
 Serial.begin ( 9600 );
}

void loop()
 unsigned long currentMillis = millis();
 if (timeElapse(timeNow, previousMillis, interval) )doSomething ();
}

void doSomething ()
{
 Serial.print ( interval / 1000 );
 Serial.println ( " second had passed since last update" );
}

boolean timeElapse( unsigned long timeNow, unsigned long &timePrevious, unsigned long timeDelay) {
 if ( timeNow - timePrevious >= timeDelay ) {
   timePrevious = timeNow;
   return 1;
 }
 return 0;
}

So now what do you think??

@AShraf

Interesting approach indeed

Would suggest to modify your macros as such just to be on the safe side

#define second(x) (((unsigned long) (x))*1000UL)
#define minute(x) (((unsigned long) (x))*60000UL)
#define hour(x) (((unsigned long) (x))*3600000UL)
#define day(x) (((unsigned long) (x))*86400000UL)

ido8780:
I am trying to do kind of two actions at the same time.

Have a look at the demo Several Things at a Time

It's one of the many interesting things in the Useful Links page

...R

on the side note if Anyone of the programming guru could answer a question I have:

why cant we just write a define such as:

#define second(x) x*1000
#define minute(x) x*second(60)
#define hour(x) x*minute(60)
#define day(x) x*hour(24)

when I do a small test program such as this

#define second(x) x*1000
#define minute(x) x*second(60)
#define hour(x) x*minute(60)
#define day(x) x*hour(24)

const long interval = minute(1); 

void setup() {
 Serial.begin ( 9600 );
 Serial.println(interval);
}

void loop()
{
}

the value that Im getting is a negative..

Why is that and Is there a way for me to do define such as the one above?

Try this code

#define _second(x) x*1000
#define _minute(x) x*_second(60)
#define _hour(x) x*_minute(60)
#define _day(x) x*_hour(24)


#define __second(x) (((unsigned long) (x))*1000UL)
#define __minute(x) (((unsigned long) (x))*60000UL)
#define __hour(x) (((unsigned long) (x))*3600000UL)
#define __day(x) (((unsigned long) (x))*86400000UL)


const long interval1 = _minute(1);
const long interval2 = __minute(1);
const long interval3 = 1 * 60 * 1000;

void setup() {
  Serial.begin ( 9600 );
  Serial.print("interval1=[");
  Serial.print(interval1);
  Serial.println("]");


  Serial.print("interval2=[");
  Serial.print(interval2);
  Serial.println("]");

  Serial.print("interval3=[");
  Serial.print(interval3);
  Serial.println("]");
}

void loop()
{
}

and you'll get may be an idea of what's going on

Hint: the compiler probably gave you a warning

don't you get a waring when you compile

warning: [b][color=red]integer overflow[/color][/b] in expression [-Woverflow] #define _second(x) x*1000

Ashraf_Zolkopli:
@ ido8780:

I feel that you are using this as a feeding device,

first of if you could use an RTC would great for you.

you could also use Time library and TimeAlarm library to work out the Timing for each day.

just in case you want to still use millis();

the way I would approach this is by understanding blink without delay example.

/* Blink without Delay

Turns on and off a light emitting diode (LED) connected to a digital
pin, without using the delay() function.  This means that other code
can run at the same time without being interrupted by the LED code.

The circuit:

  • LED attached from pin 13 to ground.
  • Note: on most Arduinos, there is already an LED on the board
    that's attached to pin 13, so no hardware is needed for this example.

created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
modified 11 Nov 2013
by Scott Fitzgerald

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/

// constants won't change. Used here to set a pin number :
const int ledPin =  13;      // the number of the LED pin

// Variables will change :
int ledState = LOW;            // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = 1000;          // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

// check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

// if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

// set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}





now what happen if I just have this ?


unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = 1000;          // interval at which to blink (milliseconds)

void setup() {
  Serial.begin ( 9600 );
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval)
  {
  previousMillis = currentMillis;
  Serial.print ( interval / 1000 );
  Serial.println ( " second had passed since last update" );
    }
}




amazing what possibility that we could now do;

what if we change the Serial.print into a function?



unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = 1000;          // interval at which to blink (milliseconds)

void setup() {
  Serial.begin ( 9600 );
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval)
  {
  previousMillis = currentMillis;
  doSomething ();
    }
}

void doSomething ()
{
  Serial.print ( interval / 1000 );
  Serial.println ( " second had passed since last update" );
}




now the function could be doing anything you like, This is just an example...

now how about we add some definition on top of the code, thing that define whats a day, hour, minute, second is.



#define second(x) x1000
#define minute(x) x
60000
#define hour(x) x3600000
#define day(x) x
86400000




with this definition on top of my code, I think I could do something simple like 



#define second(x) x1000
#define minute(x) x
60000
#define hour(x) x3600000
#define day(x) x
86400000

unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = second(1);          // interval at which to blink

void setup() {
  Serial.begin ( 9600 );
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval)
  {
  previousMillis = currentMillis;
  doSomething ();
    }
}

void doSomething ()
{
  Serial.print ( interval / 1000 );
  Serial.println ( " second had passed since last update" );
}




I think you'll see the functionality you wanted with the last example


lets make it more interesting?



#define second(x) x1000
#define minute(x) x
60000
#define hour(x) x3600000
#define day(x) x
86400000

unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = second(1);          // interval at which to blink

void setup() {
Serial.begin ( 9600 );
}

void loop()
unsigned long currentMillis = millis();
if (timeElapse(timeNow, previousMillis, interval) )doSomething ();
}

void doSomething ()
{
Serial.print ( interval / 1000 );
Serial.println ( " second had passed since last update" );
}

boolean timeElapse( unsigned long timeNow, unsigned long &timePrevious, unsigned long timeDelay) {
if ( timeNow - timePrevious >= timeDelay ) {
  timePrevious = timeNow;
  return 1;
}
return 0;
}




So now what do you think??

Hi listen I did what you say and its worked for me but when I put it in my code its not work, the problem its that the servo not repeat 7 time on the process
Here my code, I didnt notice everything yet because i didnt succes and i noitce only when i succes:

#include <IRremote.h>//Include IRremote library
#include <Servo.h>//Include Servo library

#define second(x) x*1000
#define minute(x) x*60000
#define hour(x) x*3600000
#define day(x) x*86400000

//Time
unsigned long previousMillis = 0;
const long bettwenTime = second(5);

//setting pins
//HIGH == LOW in ledone and ledt because i wired opsiate
int ledone = 12;//Set led one pin is 12
int ledt = 8;//Set led two pin is 8
int RECV_PIN = 11;//set reciver pin is 11
int servopin = 9;

Servo Mikeyservo;
IRrecv irrecv(RECV_PIN);//Set that reciver is from reciver group
decode_results results;

//Setup
void setup()
{
  Mikeyservo.attach(servopin);//Attach the servo to pin 9
  Mikeyservo.write(0);//Rest the servo
  Serial.begin(9600);//Turn on Serial
  irrecv.enableIRIn(); //Start the receiver
  pinMode(ledone,OUTPUT);//Set led one pin as Output
  pinMode(ledt,OUTPUT);//Set led two pin as Output
  digitalWrite(ledone, HIGH);//Turn off the leds Look up
  digitalWrite(ledt, HIGH);// ^
  
}

void feedingMikey()
{
      functionGo();
      Serial.println("happened");
}

void functionGo(){
       delay(1000);
       Mikeyservo.write(185);//Switch the servo to feed Mikey
       delay(1000);//Wait 1 seconed
       Mikeyservo.write(0);//Rest the servo
  }

void loop() {
  unsigned long currentMillis = millis();
  //Reciver
  if (irrecv.decode(&results))//Check if the reciver get results
  {
    Serial.println(results.value,DEC);
      
        if(results.value == 557583603)//557583603 = button 1
        {
          Serial.println("Button One has been pressed");
          delay(20);
          if(digitalRead(ledone) == HIGH)
          {
            digitalWrite(ledone, LOW);
            delay(20);//Debounce
          }
      
          else
          {
            digitalWrite(ledone, HIGH);
            delay(20);//Debounce
          }
        }
        irrecv.resume();//Resume the reciver
    
        if(results.value == 557618283)//557618283 = button 2
        {
          Serial.println("Button two has benn pressed");
      
          if(digitalRead(ledt) == HIGH)
          {
            digitalWrite(ledt,LOW);
            delay(20);//Debounce
          }
      
          else
          {  
            digitalWrite(ledt,HIGH);
            delay(20);//Debounce
          }
        }
        irrecv.resume();//Resume the reciver
        if(results.value == 557620323)//557620323 = Button 3
        {
          for(int i=0;i<=7;i++)
          {
             if(currentMillis - previousMillis >= bettwenTime)
                {
                  previousMillis = currentMillis;
                  Serial.println("Button three has been pressed");  
                  feedingMikey();  
                }
          }  
        }
  }
}

@J-M-L:

I guess actually the definition I'm looking for are the following :

#define second(x) ( ((unsigned long) x)*1000)
#define minute(x) ( ((unsigned long) x)*second(60))
#define hour(x) ( ((unsigned long) x)*minute(60))
#define day(x) ( ((unsigned long) x)*hour(24))

I see that the cast unsigned long is required and the bracket helps too.

Thanks, Heres a Karma for your help..

Ouh yeah for question, It uploaded just find and without any error.

ido8780:
my code is very long and it will for you like a mess but do you want i post him?

We don't have problems with long code. Better than a snippet where we have to guess half of the stuff.

When posting code, please use code tags.

type
** **[code]** **

paste your code after that
type
** **[/code]** **
after that

There is a limit of 9000 characters for a single post; if you exceed that, post the code in two posts or attach it.

sterretje:
We don't have problems with long code. Better than a snippet where we have to guess half of the stuff.

When posting code, please use code tags.

type
** **[code]** **

paste your code after that
type
** **[/code]** **
after that

There is a limit of 9000 characters for a single post; if you exceed that, post the code in two posts or attach it.

I am already have posted the code but here again, I will repeat the problem because you probably didnt saw so the problem is that i can do sevral things at the time but now I cant repeat that I am trying repeat that 7 times,its will be hard to understand so better for you read the post and all the comments.
Here the code:

#include <IRremote.h>//Include IRremote library
#include <Servo.h>//Include Servo library

#define second(x) x*1000
#define minute(x) x*60000
#define hour(x) x*3600000
#define day(x) x*86400000

//Time
unsigned long previousMillis = 0;
const long bettwenTime = second(5);

//setting pins
//HIGH == LOW in ledone and ledt because i wired opsiate
int ledone = 12;//Set led one pin is 12
int ledt = 8;//Set led two pin is 8
int RECV_PIN = 11;//set reciver pin is 11
int servopin = 9;

Servo Mikeyservo;
IRrecv irrecv(RECV_PIN);//Set that reciver is from reciver group
decode_results results;

//Setup
void setup()
{
  Mikeyservo.attach(servopin);//Attach the servo to pin 9
  Mikeyservo.write(0);//Rest the servo
  Serial.begin(9600);//Turn on Serial
  irrecv.enableIRIn(); //Start the receiver
  pinMode(ledone,OUTPUT);//Set led one pin as Output
  pinMode(ledt,OUTPUT);//Set led two pin as Output
  digitalWrite(ledone, HIGH);//Turn off the leds Look up
  digitalWrite(ledt, HIGH);// ^
  
}

void feedingMikey()
{
      functionGo();
      Serial.println("happened");
}

void functionGo(){
       delay(1000);
       Mikeyservo.write(185);//Switch the servo to feed Mikey
       delay(1000);//Wait 1 seconed
       Mikeyservo.write(0);//Rest the servo
  }

void loop() {
  unsigned long currentMillis = millis();
  //Reciver
  if (irrecv.decode(&results))//Check if the reciver get results
  {
    Serial.println(results.value,DEC);
      
        if(results.value == 557583603)//557583603 = button 1
        {
          Serial.println("Button One has been pressed");
          delay(20);
          if(digitalRead(ledone) == HIGH)
          {
            digitalWrite(ledone, LOW);
            delay(20);//Debounce
          }
      
          else
          {
            digitalWrite(ledone, HIGH);
            delay(20);//Debounce
          }
        }
        irrecv.resume();//Resume the reciver
    
        if(results.value == 557618283)//557618283 = button 2
        {
          Serial.println("Button two has benn pressed");
      
          if(digitalRead(ledt) == HIGH)
          {
            digitalWrite(ledt,LOW);
            delay(20);//Debounce
          }
      
          else
          {  
            digitalWrite(ledt,HIGH);
            delay(20);//Debounce
          }
        }
        irrecv.resume();//Resume the reciver
        if(results.value == 557620323)//557620323 = Button 3
        {
          for(int i=0;i<=7;i++)
          {
             if(currentMillis - previousMillis >= bettwenTime)
                {
                  previousMillis = currentMillis;
                  Serial.println("Button three has been pressed");  
                  feedingMikey();  
                }
          }  
        }
  }
}

Do you want to repeat the servo movement 7 times in sequence? Then move your for loop into feedingMikey instead of trying to call the function 7 times.

Gabriel_swe:
Do you want to repeat the servo movement 7 times in sequence? Then move your for loop into feedingMikey instead of trying to call the function 7 times.

Yes I want but i tried it to and its switch the servo only one time look in my code maybe I am wrong in something:

#include <IRremote.h>//Include IRremote library
#include <Servo.h>//Include Servo library

#define second(x) x*1000
#define minute(x) x*60000
#define hour(x) x*3600000
#define day(x) x*86400000

//Time
unsigned long previousMillis = 0;
const long bettwenTime = second(1);

//setting pins
//HIGH == LOW in ledone and ledt because i wired opsiate
int ledone = 12;//Set led one pin is 12
int ledt = 8;//Set led two pin is 8
int RECV_PIN = 11;//set reciver pin is 11
int servopin = 9;

Servo Mikeyservo;
IRrecv irrecv(RECV_PIN);//Set that reciver is from reciver group
decode_results results;

//Setup
void setup()
{
  Mikeyservo.attach(servopin);//Attach the servo to pin 9
  Mikeyservo.write(0);//Rest the servo
  Serial.begin(9600);//Turn on Serial
  irrecv.enableIRIn(); //Start the receiver
  pinMode(ledone,OUTPUT);//Set led one pin as Output
  pinMode(ledt,OUTPUT);//Set led two pin as Output
  digitalWrite(ledone, HIGH);//Turn off the leds Look up
  digitalWrite(ledt, HIGH);// ^
  
}

void feedingMikey()
{
    unsigned long currentMillis = millis();
    for(int i=0;i<=7;i++)
     {
        if(currentMillis - previousMillis >= bettwenTime)
        {
          previousMillis = currentMillis;
          functionGo();
          Serial.println("happened");
        }
     }
}

void functionGo(){
       delay(1000);
       Mikeyservo.write(185);//Switch the servo to feed Mikey
       delay(1000);//Wait 1 seconed
       Mikeyservo.write(0);//Rest the servo
  }

void loop() {
  //Reciver
  if (irrecv.decode(&results))//Check if the reciver get results
  {
    Serial.println(results.value,DEC);
      
        if(results.value == 557583603)//557583603 = button 1
        {
          Serial.println("Button One has been pressed");
          delay(20);
          if(digitalRead(ledone) == HIGH)
          {
            digitalWrite(ledone, LOW);
            delay(20);//Debounce
          }
      
          else
          {
            digitalWrite(ledone, HIGH);
            delay(20);//Debounce
          }
        }
        irrecv.resume();//Resume the reciver
    
        if(results.value == 557618283)//557618283 = button 2
        {
          Serial.println("Button two has benn pressed");
      
          if(digitalRead(ledt) == HIGH)
          {
            digitalWrite(ledt,LOW);
            delay(20);//Debounce
          }
      
          else
          {  
            digitalWrite(ledt,HIGH);
            delay(20);//Debounce
          }
        }
        irrecv.resume();//Resume the reciver
        if(results.value == 557620323)//557620323 = Button 3
        {
                  Serial.println("Button three has been pressed");  
                  feedingMikey();    
        }
  }
}

My mistake, funktionGo, not feedingMikey.

void functionGo() {
  for (int i = 0; i <= 7; i++) {
    delay(1000);
    Mikeyservo.write(185);//Switch the servo to feed Mikey
    delay(1000);//Wait 1 seconed
    Mikeyservo.write(0);//Rest the servo
  }
}