Using Multiple Timer

Hi guys,

First of all, let me start off my saying I have never ever done anything with arduino yet. I also have very little programming knowledge, only some Matlab and that’s all. I am more than lost at the moment.

So I have this little project that is pretty simple in fact. I am playing Gran Turismo 5 and hate Bspec (the mode where the computer actually drives the car for you). So I came up with the idea of rigging a servo to a controller. The servo would push the X and O buttons when needed.

I looked around and i found the Metro librairie which seems to be a decent timer. But I am not able to set multiple timers.
Sequence :

  • Waits for the race to end (XXXXXX ms)
  • Pushes X (servo travels to -20 and then comes back to 0) (quits prize menu)
  • Waits for the menu to load (5000 ms)
  • Pushes X (servo travels to -20 and then comes back to 0) (quits XP menu)
  • Waits for the menu to load (5000 ms)
  • Pushes O (servo travels to 20 and then comes back to 0) (goes to quit icon)
  • Waits for the menu to load (5000 ms)
  • Pushes X (servo travels to -20 and then comes back to 0) (quits driver menu)
  • Waits for the menu to load (5000 ms)
  • Pushes X (servo travels to -20 and then comes back to 0) (starts the race

loops back.

What I can do :

  • Basically I am alright with the button pushing thing. I have played with the servos and servo lib and thi part here is done.
  • I can wait for a set time (XXXXXX ms) before pushing a button. However, I am not able to run multiple timers.

Here is what I have done. again, that must be very mediocre but at least does what it’s supposed to do.

/*
 This code waits for a set time (currently 10 seconds) then activates a servo to push 
 a PS3 controller button.
 
 Current sequence :
- Waits 10 seconds
- Pushes X (+20 degree)
- Returns to 0

loops back

Wanted sequence :
- Waits 10 seconds
- Pushes X (+20 degree)
- Returns to 0
- Waits 5 seconds
- Pushes X (+20 degree)
- Returns to 0
- Waits 5 seconds
- Pushes X (+20 degree)
- Returns to 0
- Waits 5 seconds
- Pushes O (-20 degree)
- Returns to 0
- Waits 5 seconds
- Pushes X (+20 degree)
- Returns to 0
- Waits 5 seconds
- Pushes X (+20 degree)
- Returns to 0
 
 Problem is : don't know how to use multiple Metros
 */
#include <Metro.h> // Include Metro library
#include <Servo.h> // Include Servo library 

Metro courseMetro = Metro(10000); // Creates a timer set at 10000 ms (10 seconds)
Servo servo; // create servo object to control a servo

int pos = 95 ;

void setup()
{
 servo.attach(10); // attaches servo on pin 10 to servo object
 }

void loop()
{

  if (courseMetro.check() == 1) // check if the metro has passed it's interval .
  {
   for(pos = 95; pos < 115; pos += 1) // goes from 95 to 115 in steps of 1 degree    //
   {                                                                                 //
   servo.write(115); // tells the servo to go back to 95                             //
   delay(15);                                                                        // 
   }                                                                                 // Pushes X
   for(pos = 115; pos>=95; pos-=1) // // goes from 115 to 95 in steps of 1 degree    //
   {                                                                                 //
   servo.write(95); // tells the servo to go back to 95                              //
   delay(15);                                                                        //
   }                                                                                 //
  }
      
 }

Basically I would like to get help on how, and where to declare a new timer.

thx

Hi Slitcher,

What do you need the multiple timers for? Isn't it just a sequence of button presses you want to do one after the other?

Cheers
ajfisher