Consistent function-definition error

I know it's not pretty, but it's the first typed version, so forgive my sloppiness. Final version will be cleaned up.

I've gotten rid of the const int, I've moved all my functions around, prototyped them, changed them to voids, etc, and I always get

In function 'void setup()':
error: a function-definition is not allowed here before '{' token

Though it usually highlights the { for void loop () and not void setup ()

// Copyright 2007 Matthew Pace
// Animatronic drummer
// This program will start by obtaining 8 values
// 4 for each servo.  The values will represent
// as a pair a set location for the arm in 3d
// space.  It will then loop randomly choosing
// one of teh three spaces and drumming with it

const int drum_count = 4; // the number of drums we have
int pot_pin = 0; // the potentiometer used to set locations
int switch_pin = 11; // an on/off momentary switch
int servo1 = 9; // the pin used for signalling the servo that controls horizontal motion
int servo2 = 6; // the pin used for signalling the servo that controls vertical motion

int servo1_points [drum_count]; //an array of servo positions
int servo2_points [drum_count];

int cur_drum ; //the drum we are currently hitting
void hit_drum () ;

void setup ()
{
  pinMode (13, OUTPUT); // well since freeduino and decimillia have an LED built in, why not
  pinMode(switch_pin, INPUT);
  int i = 0; //for loop use and addressing the arrays of servo positions
  int pot;
  while (i < drum_count)
  {
    while (digitalRead(switch_pin) == HIGH) //we're using a pull up resistor, so it's normally high
    {
      pot=analogRead(pot_pin); // store the value of the potentiometer in pot
    }
    //when we get here, it means the momentary switch was hit just last loop
    servo1_points [i] =(int) (500*(pot/1023))+1250; //store the pot value converted into servo pwm in it's spot
    
    digitalWrite(13, HIGH); //let us know it read it via the included LED
    delay (250);            //pause for a quarter second
    digitalWrite (13, LOW);
    
        
    while (digitalRead(switch_pin) == HIGH) //we're using a pull up resistor, so it's normally high
    {
      pot=analogRead(pot_pin); // store the value of the potentiometer in pot
  }
    //when we get here, it means the momentary switch was hit just last loop
    servo2_points [i] = (int) (500*(pot/1023))+1250; //store the pot value converted into servo pwm in it's spot
  
    digitalWrite(13, HIGH); //let us know it read it via the included LED
    delay (250);            //pause for a quarter second
    digitalWrite (13, LOW);
    randomSeed (analogRead(0));
}

//that concludes the setup.  at this point
//we have 2 arrays, defining points for
//2 servos



void hit_drum ();
{
  int last_1 = millis();
  int last_2 = millis();
  int i = 20;
  digitalWrite(servo1, HIGH);
  digitalWrite(servo2, HIGH);
  boolean waiting1 = true;
  boolean waiting2 = true;
  
  // since we are controlling 2 servos, we can't send a pulse and then delay 20 ms, as the other
  // servo might get confused
  
  while ( i > 0 )
  {
    if (waiting1 && millis()-last_1 >= servo1_points[cur_drum]) // if the current millis minus the time of the last time we 
    {                                                       // sent a signal to servo1 is >= time to hold it high
      digitalWrite(servo1, LOW);                            // AND we are waiting for it to finish with its high signal
      last_1 = millis();
      waiting1=false;
    }
    if (waiting2 && millis()-last_2 >= servo2_points[cur_drum]) // if the current millis minus the time of the last time we 
    {                                                       // sent a signal to servo1 is >= time to hold it high
      digitalWrite(servo2, LOW);                            // AND we are waiting for it to finish with its high signal
      last_1 = millis();
      waiting2=false;
    }    
    if(!waiting1 && millis()-last_1 >= 20000)
    {
      digitalWrite(servo1, HIGH);
      i++;
      last_1 = millis();
    }    
    if(!waiting2 && millis()-last_2 >= 20000)
    {
      digitalWrite(servo2, HIGH);
      last_2 = millis();
    }
  }
return ;
}

void loop()
{
  cur_drum = random (0, drum_count); //won't overflow the array, as arrays start from 0, and random's max is exclusive
  hit_drum (cur_drum);
}

Hi,
there are 4 errors in your code. The compiler-messages don't really help sometimes :frowning:

  1. in function setup(). The closing brace "}" for the function definition is missing. The last "}" before the code for hit_drum starts is the one that is closing the outer while-loop.
    You can use the auto-format feature of the IDE for things like these.
    I'm a big fan doing code-formatting like this one here
void () {
    doSomething();
    if(x==0) {
      doMore();
    }
    while(beerAvailable) {
        dontDrive();
    }
}

Saves a lot of lines, and looks more structured to me. But this is almost like a "religious" topic to many developers.

  1. You have forgotten to delete a ";" after the function- definition for hit_drum
void hit_drum() ;
{
....

Typical error that only happens with your style of coding again. You copy the prototype with the ";" and since the brace is on the next line, your not noticing your error.

  1. you call the void function hit_drum() with an argument in loop.
void loop(){
  ...
  hit_drum (cur_drum);  //No! its defined as void hit_drum()
}
  1. The outer while-loop
while(i>0) {

in function hit_drum will never terminate because variable i starts at 20 and is always incremented inside the loop.

Eberhard

Thanks for the help!

The semi-colon from copying the prototype wasn't there initially, I was so buggled by the error I was tossing crap around.

I used processing (or proce55ing as it was called then) for a couple years fairly heavily, and was bummed to see the IDE's version of tab tends to screw with my formatting style... I need to start using my old text editors again.

And thanks for not forcing the more common style... When I learned to program, we were taught the way I use it, and why switch what usually works? I half-a**ed an attempt to switch for a few weeks and my code just became an unreadable combo of the two :frowning:

Much appreciated