How to combine program?? can someone help me with it

i want to combine my program with simon game n temp lcd …but i want the delay to be the same with the game…means it will run at the same time nt 1 by 1 …

SIMON GAME PROG

#include <Tone.h>
Tone speakerpin;
int starttune[] = {NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_F4, NOTE_G4};
int duration2[] = {100, 200, 100, 200, 100, 400, 100, 100, 100, 100, 200, 100, 500};
int note[] = {NOTE_C4, NOTE_C4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5};
int duration[] = {100, 100, 100, 300, 100, 300};
boolean button[] = {2, 3, 4, 5}; //The four button input pins
boolean ledpin[] = {8, 9, 10, 11};  // LED pins
int turn = 0;  // turn counter
int buttonstate = 0;  // button state checker
int randomArray[100]; //Intentionally long to store up to 100 inputs (doubtful anyone will get this far)
int inputArray[100]; 


void setup()
{
  Serial.begin(9600);
  speakerpin.begin(13); // speaker is on pin 13

  for(int x=0; x<4; x++)  // LED pins are outputs
  {
    pinMode(ledpin[x], OUTPUT);
  }
 
  for(int x=0; x<4; x++)
  {
    pinMode(button[x], INPUT);  // button pins are inputs
    digitalWrite(button[x], HIGH);  // enable internal pullup; buttons start in high position; logic reversed
  }

  randomSeed(analogRead(0)); //Added to generate "more randomness" with the randomArray for the output function
  for (int thisNote = 0; thisNote < 13; thisNote ++) {
     // play the next note:
     speakerpin.play(starttune[thisNote]);
     // hold the note:
     if (thisNote==0 || thisNote==2 || thisNote==4 || thisNote== 6)
     {
       digitalWrite(ledpin[0], HIGH);
     }
     if (thisNote==1 || thisNote==3 || thisNote==5 || thisNote== 7 || thisNote==9 || thisNote==11)
     {
       digitalWrite(ledpin[1], HIGH);
     }
     if (thisNote==8 || thisNote==12)
     {
       digitalWrite(ledpin[2], HIGH);
     } 
     if (thisNote==10)
     {  
       digitalWrite(ledpin[3], HIGH);
     }
     delay(duration2[thisNote]);
     // stop for the next note:
     speakerpin.stop();
     digitalWrite(ledpin[0], LOW);
     digitalWrite(ledpin[1], LOW);
     digitalWrite(ledpin[2], LOW);
     digitalWrite(ledpin[3], LOW);
     delay(25);
    }
  delay(1000);
}

void loop()
{  
  for (int y=0; y<=99; y++)
  {
    //function for generating the array to be matched by the player
    digitalWrite(ledpin[0], HIGH);
    digitalWrite(ledpin[1], HIGH);
    digitalWrite(ledpin[2], HIGH);
    digitalWrite(ledpin[3], HIGH);
 
    for (int thisNote = 0; thisNote < 6; thisNote ++) {
     // play the next note:
     speakerpin.play(note[thisNote]);
     // hold the note:
     delay(duration[thisNote]);
     // stop for the next note:
     speakerpin.stop();
     delay(25);
    }
   
    digitalWrite(ledpin[0], LOW);
    digitalWrite(ledpin[1], LOW);
    digitalWrite(ledpin[2], LOW);
    digitalWrite(ledpin[3], LOW);
    delay(1000);
 
    for (int y=turn; y <= turn; y++)
    { //Limited by the turn variable
      Serial.println(""); //Some serial output to follow along
      Serial.print("Turn: ");
      Serial.print(y);
      Serial.println("");
      randomArray[y] = random(1, 5); //Assigning a random number (1-4) to the randomArray[y], y being the turn count
      for (int x=0; x <= turn; x++)
      {
        Serial.print(randomArray[x]);
     
        for(int y=0; y<4; y++)
        {
     
          if (randomArray[x] == 1 && ledpin[y] == 8)
          {  //if statements to display the stored values in the array
            digitalWrite(ledpin[y], HIGH);
            speakerpin.play(NOTE_G3, 100);
            delay(400);
            digitalWrite(ledpin[y], LOW);
            delay(100);
          }

          if (randomArray[x] == 2 && ledpin[y] == 9)
          {
            digitalWrite(ledpin[y], HIGH);
            speakerpin.play(NOTE_A3, 100);
            delay(400);
            digitalWrite(ledpin[y], LOW);
            delay(100);
          }
 
          if (randomArray[x] == 3 && ledpin[y] == 10)
          {
            digitalWrite(ledpin[y], HIGH);
            speakerpin.play(NOTE_B3, 100);
            delay(400);
            digitalWrite(ledpin[y], LOW);
            delay(100);
          }

          if (randomArray[x] == 4 && ledpin[y] == 11)
          {
            digitalWrite(ledpin[y], HIGH);
            speakerpin.play(NOTE_C4, 100);
            delay(400);
            digitalWrite(ledpin[y], LOW);
            delay(100);
          }
        }
      }
    }
    input();
  }
}



void input() { //Function for allowing user input and checking input against the generated array

  for (int x=0; x <= turn;)
  { //Statement controlled by turn count

    for(int y=0; y<4; y++)
    {
     
      buttonstate = digitalRead(button[y]);
   
      if (buttonstate == LOW && button[y] == 2)
      { //Checking for button push
        digitalWrite(ledpin[0], HIGH);
        speakerpin.play(NOTE_G3, 100);
        delay(200);
        digitalWrite(ledpin[0], LOW);
        inputArray[x] = 1;
        delay(250);
        Serial.print(" ");
        Serial.print(1);
        if (inputArray[x] != randomArray[x]) { //Checks value input by user and checks it against
          fail();                              //the value in the same spot on the generated array
        }                                      //The fail function is called if it does not match
        x++;
      }
       if (buttonstate == LOW && button[y] == 3)
      {
        digitalWrite(ledpin[1], HIGH);
        speakerpin.play(NOTE_A3, 100);
        delay(200);
        digitalWrite(ledpin[1], LOW);
        inputArray[x] = 2;
        delay(250);
        Serial.print(" ");
        Serial.print(2);
        if (inputArray[x] != randomArray[x]) {
          fail();
        }
        x++;
      }

      if (buttonstate == LOW && button[y] == 4)
      {
        digitalWrite(ledpin[2], HIGH);
        speakerpin.play(NOTE_B3, 100);
        delay(200);
        digitalWrite(ledpin[2], LOW);
        inputArray[x] = 3;
        delay(250);
        Serial.print(" ");
        Serial.print(3);
        if (inputArray[x] != randomArray[x]) {
          fail();
        }
        x++;
      }

      if (buttonstate == LOW && button[y] == 5)
      {
        digitalWrite(ledpin[3], HIGH);
        speakerpin.play(NOTE_C4, 100);
        delay(200);
        digitalWrite(ledpin[3], LOW);
        inputArray[x] = 4;
        delay(250);
        Serial.print(" ");
        Serial.print(4);
        if (inputArray[x] != randomArray[x])
        {
          fail();
        }
        x++;
      }
    }
  }
  delay(500);
  turn++; //Increments the turn count, also the last action before starting the output function over again
}

void fail() { //Function used if the player fails to match the sequence

  for (int y=0; y<=2; y++)
  { //Flashes lights for failure
   
    digitalWrite(ledpin[0], HIGH);
    digitalWrite(ledpin[1], HIGH);
    digitalWrite(ledpin[2], HIGH);
    digitalWrite(ledpin[3], HIGH);
    speakerpin.play(NOTE_G3, 300);
    delay(200);
    digitalWrite(ledpin[0], LOW);
    digitalWrite(ledpin[1], LOW);
    digitalWrite(ledpin[2], LOW);
    digitalWrite(ledpin[3], LOW);
    speakerpin.play(NOTE_C3, 300);
    delay(200);
  }
  delay(500);
  turn = -1; //Resets turn value so the game starts over without need for a reset button
}

TEMP SENSOR LCD Program

#include <LiquidCrystal.h>  // include the LCD driver library

//declare variables
float tempC = 0;  // variable for holding Celcius temp (floating for decimal points precision)
float tempf = 0;  // variable for holding Fareghneit temp
int tempPin = 0;  // Declaring the Analog input to be 0 (A0) of Arduino board.
float samples[8]; // array to hold 8 samples for Average temp calculation
float maxi = -100,mini = 100; // max/min temperature variables with initial values. LM35 in simple setup only measures Temp above 0.
int i;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(28, 29, 30, 31, 32, 33);


void setup()
{
  Serial.begin(9600); // start serial communication
  lcd.begin(16, 2); // set up the LCD's number of columns and rows: 

  lcd.setCursor(0, 0); // set LCD cursor position (column, row)
  lcd.print("Hello "); // print text to LCD
  lcd.setCursor(0, 1);
  lcd.print("Elderly project");
  delay(5000); // wait 500ms
  lcd.clear(); // clear LCD display
  lcd.setCursor(0, 0);
  lcd.print("LCD Temp");
  lcd.setCursor(0, 1);
  lcd.print(" Digital Monitor ");                                                                                                                                                                                                                                                                                                                                                                                                                              
  delay(4000);
  lcd.clear();
}

void loop()
{
  
  Serial.println(analogRead(tempPin));
for(i = 0;i<=7;i++){ // gets 8 samples of temperature
  
samples[i] = ( 4.4 * analogRead(tempPin) * 100.0) / 1024.0;
  
Serial.print(".");
lcd.setCursor(0, 0); // set LCD cursor position
lcd.print("Current T: "); // print to LCD
lcd.setCursor(12, 0); 
lcd.print(samples[i]);
tempC = tempC + samples[i];
  delay(800);
}
Serial.println(""); // Like and CR at serial monitor
Serial.println("");
tempC = tempC/8.0; // better precision
tempf = (tempC* 9)/ 5 + 32; // converts to fahrenheit

if(tempC > maxi) {maxi = tempC;} // set max temperature
if(tempC < mini) {mini = tempC;} // set min temperature

// Send Results to Serial Monitor
Serial.println("New measurement");
Serial.print(" Average Temperature in Celcius is " );             //send the data to the computer
Serial.println(tempC);//send the data to the computer
Serial.print(" Average Temperature in Farenait is " );             //send the data to the computer
Serial.println(tempf);//send the data to the computer
Serial.print(" MAX Temperature in Celcius is " );             //send the data to the computer
Serial.println(maxi);//send the data to the computer
Serial.print(" MIN Temperature in Celcius is " );             //send the data to the computer
Serial.println(mini);//send the data to the computer

// Send results to LCD.
lcd.setCursor(0, 0);
lcd.print("Av.T   Max   Min");

// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the measured temp average
lcd.print(tempC);
lcd.setCursor(6, 1);
// print the maximum temp 
lcd.print(maxi);
lcd.setCursor(12, 1);
// print the minimum temp 
lcd.print(mini);
digitalWrite(13, HIGH);    // set the LED off
delay(2000);   // Wait about 3 seconds to display the results to LCD screen befor starting the loop again
tempC = 0; // Set tempC to 0 so calculations can be done again

}

Read this before posting a programming question

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the # button above the posting area.

any kind soul can help me asap??

delay(2000);   // Wait about 3 seconds

For various reasons, any statement like that has to go. When is our assignment due?

AWOL: delay(2000);   // Wait about 3 seconds

For various reasons, any statement like that has to go. When is our assignment due?

thursday :(

any kind soul can help me asap??

delay(2000);   // Wait about 3 seconds

This is ironic. 8)

any soul help me pls????

What have you tried?

Show us your attempts at combining them.

Combining is essentially just interleaving the two, but the first thing you need is both codes to be kosher. The simon one baulks at the second line Tone speakerpin and won't compile.

i tried it combine but it only works 1 step by 1 step i dunno how to do the loop together

all_together.ino (11 KB)

samples[i] = ( 4.4 * analogRead(tempPin) * 100.0) / 1024.0; // conversion math of LM35 sample to readable temperature and stores result to samples array. 1024 is the Bit depth (quantization) of Arduino.
// 5 is the supply volts of LM35. Change appropriatelly to have correct measurement. My case is 4.4Volts.

If your Arduino is operating at 4.4 volts, it’s either damaged or needs new batteries powering it. It should be at very close to 5.0 V or 3.3 V, depending on which Arduino you have.

int randomArray[100]; //Intentionally long to store up to 100 inputs (doubtful anyone will get this far)
int inputArray[100];

That’s 400 bytes of the 2048 that you have available.

    for (int y=turn; y <= turn; y++)
    { //Limited by the turn variable

How many times is this going to loop?

i tried it combine but it only works 1 step by 1 step i dunno how to do the loop together

You need to do more than say that you are frustrated. You need to say exactly what the code does, and does not, do.

mian91: i tried it combine but it only works 1 step by 1 step i dunno how to do the loop together

Did it compile OK?

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(28, 29, 30, 31, 32, 33);

What Arduino do you have?

People, I fear we may be too late. See reply #6.

He didn't say which Thursday. :P

Besides, it's still Thursday here. Late Thursday, admittedly.

The OP might want to Google "assignment extension".

[quote author=Nick Gammon link=topic=130611.msg996989#msg996989 date=1352977195]

mian91: i tried it combine but it only works 1 step by 1 step i dunno how to do the loop together

Did it compile OK? [/quote]

yes no error

[quote author=Nick Gammon link=topic=130611.msg996990#msg996990 date=1352977268]

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(28, 29, 30, 31, 32, 33);

What Arduino do you have? [/quote]

i using arduino mega

AWOL: People, I fear we may be too late. See reply #6.

i have few more weeks before i grauate fyi.....last thursday was my presentation i did not show the combine codes