Two Sketches combined but won't play well

Hi,
I am an utter Noob to Arduino, I know the basics and I work with electronics however never really got around to coding Arduino stuff. Anyway for a few days I have been working with a Doorbell project that sends an email and a Tweet when someone rings my bell. It also sends an image VIA PushingBox.com from my Foscam FI8918W camera...all that works great and everything setup OK, I now wanted to use some doorbell code to actually make some noise...I tried to combine the two codes but run into a brick wall....I get to a point and I am way out of my depth....the code is below and I am sure it will take a few seconds to fix...but I am a noob.....I could read 100 tutorials but still be back clueless.

The code is below and it runs but conks out at void loop ()( with only 5 errors I think.....help needed please...

Anywho.....this is the Ino file attached as I can't post the whole code here....please be gentle as I am bound to get "back to skool pleese" and all that....

Thanks kind regards Spence

Spencers_Doorbell.ino (141 KB)

Have you read what it says here:-
http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html

I am getting:-

PCM.h: No such file or directory

Wo have you a link to the library file you are using?

Sounds like you have a fun project. You should supply the two separate working code. I just read Mike's tutorial. It's quite informative. It deals with merging two projects together. What I sense you were trying to do is simply adding a function to an existing project. The project already works and needs something a lot less complex added to it, not like two equals merging (lots of layoffs :D).

OK let me quickly answer all the questions, Yes read everything in thattutorial and that's how got to this point but even after doing the copy paste I got stuck. The Zip for the PCM include is attached and I also attached the two ino's that I want to merge. Many thanks guys I feel inspired and compelled to carry on.

Many thanks kind regards Spence

PushingBox_Code.ino (3.47 KB)

DoorBellDisharmonic.ino (138 KB)

PCM_Libs.zip (3.56 KB)

Sorry for the double post but IGNORE the first DoorBellDisharmonic file as it is broken, The working one is here.....

DoorBellDisharmonic.ino (138 KB)

Thanks but I am having trouble compiling that DoorBell sketch, my compiler is still complaining about a missing PCM.h file even though I installed the library. ( and restarted the IDE ). I am using IDE 1.6.4

Not sure what to say but it is late here so I will have another look in the morning.

What Arduino are you compiling it for?

EDIT:- yes it is late, installed it in the right place and now getting some other errors, as I said in the morning.

I now think the program of the doorbell needs routins.... eeekkk.... I am rubbish at this. here is where I snuffled the DoorBell code from....

Nore it says this project is for kinds...."does not mention noobs"

http://fritzing.org/projects/mp3-sound-door-bell-wit-an-arduino

What Arduino are you compiling it for? The UNO hopefully Gnight.

OK I combined the two and it compiles, however no idea if it works it is just a simple loop1 and then loop 2 setup . I had to go to a Mega because there was not enough memory for a Uno. What error messages were you getting.
Warning, SPI uses pin 13 as does your sound code, this is an issue that needs resolving, move the pin used by the sound file.

This is just the code bit not the Routines.ino file

/* Basic code comes from:
http://hlt.media.mit.edu/?p=1963

 good Sounds to find:
http://www.handycomedy.de/
http://soundjax.com/

Copy the files in Libraries to Libraries directory!!
Door Bell Sounds 
Autor: Michael Johannes Franz
Date: 05/01/2014
http://electronic-cosmos.de/
share Alike http://creativecommons.org/licenses/by-sa/3.0/
*/ 

#include <PCM.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x19 };   // Be sure this address is unique in your network

//Your secret DevID from PushingBox.com. You can use multiple DevID  on multiple Pin if you want
char DEVID1[] = "Your_DevID_Here";        //Scenario : "The mailbox is open"

//Numeric Pin where you connect your switch
uint8_t pinDevid1 = 3; // Example : the mailbox switch is connect to the Pin 3

// Debug mode
boolean DEBUG = true;
  //////////////
 //   End    //
//////////////


// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

char serverName[] = "api.pushingbox.com";
boolean pinDevid1State = false;                // Save the last state of the Pin for DEVID1
boolean lastConnected = false;                 // State of the connection last time through the main loop

// constants:
// Audio or better speaker on pin 11
#define LedPin             13     // LED to show the action of a interrupt
#define wakePin             2     // active LOW, ground this pin momentary to wake up
// Defining the sound
const unsigned char sample[] PROGMEM = {
126, 126, 126, 127, 127, 128, 128, 128, 128, 127, 127, 128, 128, 129, 128, 128, 128, 128, 128, 128, 140, 151, 153, 151, 151, 155, 156, 148, 150, 149, 143, 145, 139, 128, 116, 107, 102, 94, 92, 100, 95, 95  // sample removed to make the post fit
};

int heartbeatledState;             // ledState used to set the LED
long heartbeatpreviousMillis;
long heartbeatinterval;
unsigned long heartbeatcurrentMillis;

void setup()
{
  pinMode(LedPin, OUTPUT);         // LED for indicating a wake up
  pinMode(wakePin, INPUT_PULLUP);  // Select Pull Up Resistor
  heartbeatinterval = 100;
  setup2();
}

void loop()
{
  loop2();
  if((digitalRead(wakePin)) == 0) {
    startPlayback(sample, sizeof(sample)); // Play the sample
    indicate();                            // Stay here as long as the sound is!
                                           // change times in indicate Function
  }
  else {
    delay(100);
    stopPlayback();                        // Stops the Function
    flash(30,1970);                        // flash without delay each 2 seconds 
  }
}

////
//
// General code from http://www.pushingbox.com for Arduino + Ethernet Shield (official) v1.2
//
////


  /////////////////
 // MODIFY HERE //
/////////////////



void setup2() {
  Serial.begin(9600);
  pinMode(pinDevid1, INPUT);
  
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }
  else{
    Serial.println("Ethernet ready");
    // print the Ethernet board/shield's IP address:
    Serial.print("My IP address: ");
    Serial.println(Ethernet.localIP());
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
}

void loop2()
{
      ////
      // Listening for the pinDevid1 state
      ////
      if (digitalRead(pinDevid1) == HIGH && pinDevid1State == false) // switch on pinDevid1 is ON 
      {
        if(DEBUG){Serial.println("pinDevid1 is HIGH");}
        pinDevid1State = true;
        //Sending request to PushingBox when the pin is HIGHT
        sendToPushingBox(DEVID1);
      }
       if (digitalRead(pinDevid1) == LOW && pinDevid1State == true) // switch on pinDevid1 is OFF
      {
        if(DEBUG){Serial.println("pinDevid1 is LOW");}
        pinDevid1State = false;
        //Sending request to PushingBox when the pin is LOW
        //sendToPushingBox(DEVID1);    //Here you can run an other scenario by creating a DEVID2 variable
      }
      
      
      //DEBUG part
      // this write the respons from PushingBox Server.
      // You should see a "200 OK"
      if (client.available()) {
        char c = client.read();
        if(DEBUG){Serial.print(c);}
      }
      
      // if there's no net connection, but there was one last time
      // through the loop, then stop the client:
      if (!client.connected() && lastConnected) {
        if(DEBUG){Serial.println();}
        if(DEBUG){Serial.println("disconnecting.");}
        client.stop();
      }
      lastConnected = client.connected();
}


//Function for sending the request to PushingBox
void sendToPushingBox(char devid[]){
  client.stop();
  if(DEBUG){Serial.println("connecting...");}

  if (client.connect(serverName, 80)) {
    if(DEBUG){Serial.println("connected");}

    if(DEBUG){Serial.println("sendind request");}
    client.print("GET /pushingbox?devid=");
    client.print(devid);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();
  } 
  else {
    if(DEBUG){Serial.println("connection failed");}
  }
}

Hi Grumpy Mike,
thanks for the information, the code now splurts out this.

Fixed_for_me.ino.ino: In function 'void loop()':
Fixed_for_me.ino:71: error: 'indicate' was not declared in this scope
Fixed_for_me.ino:77: error: 'flash' was not declared in this scope
'indicate' was not declared in this scope

Other than that is seems to compile a little further. Absolutely not rush whatsoever as my favourite UNO bit the dust last night. I think I have a bad USB cable and while it was uploading some other code it went bad and now has the L LED fading and randomly flashing even without the 328P in the socket so its either dodgy soldering or a bad component. Have ordered 5 more Nanos and 2 UNO's and a Mega as all my other Arduino boards are being used elsewhere eg: APRS Tracker, satellite tracking, Bluetooth Arduino 1200AFSK converter and other radio amateur related projects.

Many thanks for all the help up to now as I see from the other posts your a very important cog in the Arduino wheel. Most popular as far as I can tell.

Spence

PS: Changed 13 to Pin 5. all seems well but still no Mega to program it to anyway. Pleahh..

thanks for the information, the code now splurts out this.

Fixed_for_me.ino.ino: In function 'void loop()':
Fixed_for_me.ino:71: error: 'indicate' was not declared in this scope
Fixed_for_me.ino:77: error: 'flash' was not declared in this scope
'indicate' was not declared in this scope

You have forgotten to include the Routines.ino file in the same folder as your other code. When you do it will compile.

Most popular as far as I can tell.

Well second most actually. Look up PaulS.

That's brilliant, more Karma points Mike (or Kudos points). I should have some free time in work soon and perhaps I can dedicate it to reading up on some code and learning Arduino.

Many thanks and when my Mega arrives from overseas I shall give you a full report.

Thanks Mike and all the others for your continued support and perhaps one day I shall be the one to let rip with some code of my own.... ho hum.

Spence de M0STO