I got a code right here, but every time I try to stack LCD code in there, there are some errors, can anyone help me stack this code?
MY CODE
/*
Two melodies on two buttons and one speaker
Plays a melody determined by button pushed
circuit:
- 8 ohm speaker on digital pin 8
- push button on digital pin 2
- push button on digital pin 7
created 21 Jan 2010
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Tone
*/
#include "pitches.h"
// notes in the melody:
int halloweenMelody[] = {
NOTE_CS5, NOTE_FS4, NOTE_FS4, NOTE_CS5, NOTE_FS4, NOTE_FS4, NOTE_CS5, NOTE_FS4, NOTE_D5, NOTE_FS4, NOTE_CS5, NOTE_FS4, NOTE_FS4, NOTE_CS5, NOTE_FS4, NOTE_FS4, NOTE_CS5, NOTE_FS4, NOTE_D5, NOTE_FS4
};
int starwarsMelody[] = {
NOTE_G3, NOTE_G3, NOTE_G3, NOTE_D4, NOTE_G4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_C5, NOTE_G4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_C5, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_F4, NOTE_D4
};
int halloween = 13;
int starwars = 7;
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6
};
int counterDurations[] = {
6, 6, 6, 1, 1, 6, 6, 6, 1, 2, 6, 6, 6, 1, 2, 6, 6, 6, 1
};
void setup(){
//make the button's pin input
pinMode(halloween, INPUT_PULLUP);
pinMode(starwars, INPUT_PULLUP);
}
void loop() {
//if the button is pressed
if (digitalRead(halloween) == LOW) {
//iterate over the notes of the melody
for (int thisNote=0; thisNote <20; thisNote++) {
//to calculate the note duration, take one second. Divided by the note type
int noteDuration = 1000 / noteDurations [thisNote];
tone(8, halloweenMelody [thisNote], noteDuration);
//to distinguish the notes, set a minimum time between them
//the note's duration +30% seems to work well
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
//stop the tone playing
noTone(8);
} }
//if the button is pressed
if (digitalRead(starwars) == HIGH) {
//iterate over the notes of the melody
for (int thisNote=0; thisNote <19; thisNote++) {
//to calculate the note duration, take one second. Divided by the note type
int noteDuration = 1000 / counterDurations [thisNote];
tone(8, starwarsMelody [thisNote], noteDuration);
//to distinguish the notes, set a minimum time between them
//the note's duration +30% seems to work well
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
//stop the tone playing
noTone(8);
}}}
HERE IS LCD CODE
/*
SparkFun Inventor's Kit
Example sketch 15
LIQUID CRYSTAL DISPLAY (LCD)
A Liquid Crystal Display (LCD) is a sophisticated module
that can be used to display text or numeric data. The display
included in your SIK features two lines of 16 characters, and
a backlight so it can be used at night.
If you've been using the Serial Monitor to output data,
you'll find that a LCD provides many of the same benefits
without needing to drag a large computer around.
This sketch will show you how to connect an LCD to your Arduino
and display any data you wish.
This sketch was written by SparkFun Electronics,
with lots of help from the Arduino community.
This code is completely free for any use.
Visit http://learn.sparkfun.com/products/2 for SIK information.
Visit http://www.arduino.cc to learn about the Arduino.
Version 1.0 2/2013 MDG
*/
// Load the LiquidCrystal library, which will give us
// commands to interface to the LCD:
#include <LiquidCrystal.h>
// Initialize the library with the pins we're using.
// (Note that you can use different pins if needed.)
// See http://arduino.cc/en/Reference/LiquidCrystal
// for more information:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2); //Initialize the 16x2 LCD
lcd.clear(); //Clear any old data displayed on the LCD
lcd.print("Halloween"); // Display a message on the LCD!
}