Pages: [1]   Go Down
Author Topic: How do i call this routine?  (Read 863 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

searched but cannot find what i am doing wrong?

I am new to Arduino having used Basic before. I wish to use the routine do_this

I like to have things in their own routines so thought i would try something simple first, but cannot get this right?

i get "error 'ledPin' was not declared in this scope"

Code:

//-----------------------------------------------------------------------

void setup()   {  

  do_this();

  pinMode(ledPin, OUTPUT);     //error 'ledPin' was not declared in this scope
}

//-----------------------------------------------------------------------

void loop()                       
{
  // Do something
}

//----------------------------------------------------------------------

void do_this()
{
  const int ledPin =  13;    // LED connected to digital pin 13
}

//-----------------------------------------------------------------------
 



I am sure this is very simple but need a little help?


Regards

Gary
Logged

USA
Offline Offline
Full Member
***
Karma: 2
Posts: 213
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have the led = 13 line inside of a routine, that makes it a LOCAL variable and not a GLOBAL variable. Also, C requires that everything be defined BEFORE you use it.

Understand that the setup code gets called ONCE, and loop gets called forever.


Your code should look like this

Code:
//-----------------------------------------------------------------------

  const int ledPin =  13;    // LED connected to digital pin 13


void setup()   {  

  do_this();

  pinMode(ledPin, OUTPUT);     //error 'ledPin' was not declared in this scope
}

//-----------------------------------------------------------------------

void loop()                       
{
  // Do something
}

//----------------------------------------------------------------------

void do_this()
{
}

//-----------------------------------------------------------------------



Logged

Pages: [1]   Go Up
Jump to: