Pages: [1]   Go Down
Author Topic: another function problem  (Read 359 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Simple example.  I want a condition in my main loop to start another function - in this case the piece of art does certain things while at rest, then when a button is pushed it does its full show.  

void loop()  //default resting behavior
{
  if (digitalRead(inPin))   // read the switch
  {
  do some stuff;  //
  }
  else
  {
  run_main_show();
  }
}

void run_main_show() //run show script here
  {
  do some other stuff;
  }

This example is just for one button and one show, but I envision cases where I want more functions... i.e. "why not just put your code in the main loop instead of another function?" isn't the answer I'm looking for...although I suppose it may be the actual answer.

Anyway, the error I get is "'run_main_show' was not declared in this scope".  Which makes some sense, but how do I make the compiler happy when calling functions?
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 119
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that looks good to me, but there is probably some minor syntax error causing it to break.  if you post your full code i can help you track it down.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the whole thing as it sits now.  At the moment all I was doing was using the LED to try calling the other function (meaning as a diagnostic indicator).  My code for driving a serial servo controller, among other things, will eventually go in instead.

int ledPin = 13; // LED pin 13
int inPin = 7;   // switch pin 7


void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
  pinMode(inPin, INPUT);      // sets the digital pin 7 as input
}

void loop()  //default resting behavior
{
  if (digitalRead(inPin))   // read the arm switch
  {
  digitalWrite(ledPin, HIGH);
  delay (50);
  digitalWrite(ledPin, LOW);
  delay (50);
  }
  else
  {
  run_main_show();
  }
}

void run_main_show() //run show script here
  {
  digitalWrite(ledPin, HIGH);
  delay (5000);
  }
« Last Edit: November 15, 2007, 02:35:04 pm by CTP » Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

My guess is that the //run show script here comment is confusing the Arduino IDE when it attempts to generate prototypes for the functions in your code.  Normally, in C/C++ you need to declare a function before you use it, but we didn't want to make people do this.  Unfortunately, our automatic prototyper doesn't always work so well.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

argh...LOL...twice now I'm doing everything right and some little weird thing gets me.  BTW - Is there a way in Arduino to explicitly declare a function?  Not that I need it, just curious.


Ah well, away I go.  I doubt you've heard the last of me - I have to get this piece ready to go to Vienna with me Wednesday morning.  Nothing like a deadline to help learn a new programming language, eh?  ;D


Many thanks!
« Last Edit: November 15, 2007, 08:36:11 pm by CTP » Logged

Pages: [1]   Go Up
Jump to: