Pages: [1]   Go Down
Author Topic: subrutine  (Read 454 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How can i call a subrutine,a section of my program is repeatted a lot of time?
Logged

Offline Offline
Full Member
***
Karma: 11
Posts: 168
IDE for Microsoft Visual Studio and Atmel Studio 6.1, optional USB Debugger
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

//the loop() function is called by arduino. when it ends it is called again, and again and again...
int i=0;
void loop()
{
  //call a subroutine
   DoSomething();
  //and another one
   DoSomethingElse();

  //or you can make your own looping. we loop 10 times
  int n=0;
  for(n=0;n<10;n++)
   {
      DoSomething();
      DoSomethingElse()
   }

}

void DoSomething()
{
  //do some stuff here
  i++;
}

void DoSomethingElse()
{
  //do some stuff here
  i--;
}

//the code above should add 1 to i and then subtract 1 from i continuously
« Last Edit: February 17, 2012, 05:22:59 pm by Visual Micro » Logged

Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

West Des Moines, Iowa USA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have any programming experience and if so, in what language(s)? This is so basic that it'd help to know at what level to answer...
Logged

There's always a better way!

Smithfield, Rhode Island
Offline Offline
God Member
*****
Karma: 3
Posts: 843
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I recall correctly from many years ago, I think BASIC used the term "subroutine". Beginner questions are okay, we were all beginners once.
Logged

Pages: [1]   Go Up
Jump to: