Trying to code a function and not getting it.

Attached is my code. I am trying to create a bit of code to control a door bell with solenoid chimes. Being a programmer from way back, I wanted to condense the code and make it easier to add more later so I am trying to set up a function called ‘PlayIt’ that simply activates the solenoid, pauses, deactivates it and the pause for the varible duration. When I try to compile the code I get the following error messages:

DoorBell2:20: error: variable or field ‘PlayIt’ declared void
DoorBell2:20: error: ‘ChimeN’ was not declared in this scope
DoorBell2:20: error: ‘HowLong’ was not declared in this scope
DoorBell2.cpp: In function ‘void loop()’:
DoorBell2:61: error: ‘PlayIt’ was not declared in this scope
DoorBell2.cpp: At global scope:
DoorBell2:95: error: variable or field ‘PlayIt’ declared void

And here is my code:

/* 
 Door Bell Chimes
 
 This code is used to replace faulty Chime style door bell systems that
utilize solenoids and 16v transformer. 
 
 The circuit:
 * 16v AC from transformer is split to drive the solenoids and to a bridge rectifier
 * 16v DC current stepped down to 9v to drive Arduino
 * Each chime uses a transistor to drive the solenoid activated by specific pin out
 * Pins 1,2,3 & 4 used to drive switch transistors
 * Pins 11, 12 and 13 used to receive signal from front, spa and game room doors
 
 created January 2012
 by Rusty Key
 
This example code is in the public domain.
 
 */

// Set input pins
int Front = 11;    // the number of the pushbutton pin
int Spa = 12;     // the number of the pushbutton pin
int Game = 13;    // the number of the pushbutton pin
// set output pin numbers:
int Chime1 =  1;      // the number of the lowest chime
int Chime2 =  2;      // the number of the mid-low chime
int Chime3 =  3;      // the number of the mid-high chime
int Chime4 =  4;      // the number of the highest chime

// Variables 
int Which = 0;             // the current reading from the input pin
int HowLong = 0;        // how long to delay between notes
int ChimeN = 0;         // which chime number to ring

void setup() {
  pinMode(Front, INPUT);
  pinMode(Spa, INPUT);
  pinMode(Game, INPUT);
  pinMode(Chime1, OUTPUT);
  pinMode(Chime2, OUTPUT);
  pinMode(Chime3, OUTPUT);
  pinMode(Chime4, OUTPUT);
}

void loop() {
  // read the state of each switch and if on set varible to button
  // not worried about two buttons being pressed at the same time
  
  int reading = digitalRead(Front);
  if (reading == HIGH) Which = 11;
 
  reading = digitalRead(Spa);
  if (reading == HIGH) Which = 12;
 
  reading = digitalRead(Game);
  if (reading == HIGH) Which = 13;

  switch (Which) {
    case 11:
     //Front door button - ring westminster
     PlayIt(1, 300);
     PlayIt(3, 300);
     PlayIt(2, 300);
     PlayIt(4, 400);
     PlayIt(4, 300);
     PlayIt(2, 300);
     PlayIt(1, 300);
     PlayIt(3, 300);
     Which = 0;
     break;
    case 12:
     //Back door button - ring two tone chime
     PlayIt(3, 300);
     PlayIt(4, 300);
     Which = 0;
     break;
    case 13:
     //Game door button - ring Shave and a haircut
     PlayIt(1, 300);
     PlayIt(3, 200);
     PlayIt(3, 200);
     PlayIt(2, 300);
     PlayIt(3, 100);
     Which = 0;
     break;
    default:
     // No button pushed
     delay(50);
    }
  
  // Clear the door variable just because
  Which = 0;
}

void PlayIt(ChimeN, HowLong) {
  digitalWrite(ChimeN, HIGH); // activate solenoid
  delay(50);  // keep it hot long enough to strike
  digitalWrite(ChimeN, LOW);  // turn off solenoid
  delay(HowLong);  // allow to chime to ring
}

Any help would be greatly appreciated!

You need to declare the types of your function parameters, e.g.

void PlayIt(int ChimeN, unsigned int HowLong) {

dc42 is correct. Also define PlayIt before loop(). If you want it after loop(), add its declaration before loop():

void PlayIt(int ChimeN, unsigned int HowLong);
[\code]

Thats how it used to be in C. Can't say for sure about C compiler for arduino.

On Arduino you don't have to worry about where a function is declared, the IDE scans the code and inserts declarations AFAIK.

It still has to be declared correctly though :)


Rob