Go Down

Topic: subrutine (Read 469 times) previous topic - next topic

artmeder

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

Visual Micro

#1
Feb 17, 2012, 11:16 pm Last Edit: Feb 17, 2012, 11:22 pm by Visual Micro Reason: 1
//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
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

Morris Dovey

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...
There's always a better way!

skyjumper

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

Go Up