i am trying to get the voice shield to play the pre recorded sound when the keypad is pushed on the sender. the voice shield is on the receiver, and i am also having issues getting the info to display on the LCD screen, the only thing i see on the LCD screen is -1 and i dont know why.
sender code
//Sender
#include <Wire.h>
#include <SoftwareSerial.h>
#include <Keypad.h> //This is the library for the key pad
#include <TinyGPS.h>
//#include<VoiceShield.h>
const int inPin=A0;
float temp;
int tempPin = A0;
const int heartratePin = A1;
int difference;
int newHeartReading = 0;
int lastHeartReading = 0;
int measurements[5] = {0,0,0,0,0};
int historySize = 5;
int recenttotal = 0;
int Index = 0;
boolean highChange = false;
int minimumdifference = 2;
int num[5];
int average=0;
SoftwareSerial GPS(11,12); // configure software serial port
TinyGPS shield;
// Heart rate timing
long lastHeartbeatTime = 0;
long debounceDelay = 150; // the debounce time; increase if the output flickers
int currentHeartrate = 0;
int lastHeartrate = 0;
int slope = ((newHeartReading-lastHeartReading)/(debounceDelay-lastHeartrate));
// Debugging string
String debugOutput = "";
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
//byte rowPins[ROWS] = {38, 39, 40, 41}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
//byte colPins[COLS] = {42, 43, 44}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte ledPin = 13;
//VoiceShield vs(80); // Create a instance of the Voice Shield called "vs" with 80 sound slots
/*int i = 1;
int Sentence[16];
int Phs1[] = {
33, 78, 72, 255}; // "I am cold"
int Phs2[] = {
33, 78, 16}; // "I am sick"
int Phs3[] = {
33, 44, 69}; // "I want food"
*/
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
GPS.begin(9600);
Serial.begin(9600);
}
void getgps(TinyGPS &gps)
{
// Define the variables that will be used
float latitude, longitude;
// Then call this function
shield.f_get_position(&latitude, &longitude);
}
void loop()
{
int value = analogRead(inPin);
Wire.beginTransmission(4); // transmit to device #4
float millivolts = (value/1024.0)*5000;
float celsius = millivolts/10-50;
//temp = analogRead(tempPin);
//temp = temp * 0.48828125;
Wire.println("TEMPRATURE = ");
Wire.println(celsius);
Wire.println("*C");
Wire.println();
// lcd.setCursor(0,1);
Wire.println((celsius * 9)/5 +32);
Wire.println("*F");
Wire.println();
newHeartReading = analogRead(heartratePin);
// Wire.beginTransmission(1); // transmit to device #4
//calculation
difference = newHeartReading - lastHeartReading;
lastHeartReading = newHeartReading;
// Find new recent total
recenttotal = recenttotal - measurements[Index] + difference;
// replace indexed recent value
measurements[Index] = difference;
//index + 1 index = (index + 1) % historySize;
for (int i=0; i<5; i=i+1){
num[i]=0;
}
if (Index>=5)
Index=0;
//calculating the average
average=recenttotal/5;
Wire.println(average);
//delay(100);
if (recenttotal >= minimumdifference)
{
// possible heart rate check timing
if (millis() - lastHeartbeatTime >= debounceDelay) // whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
{
// Heart rate
currentHeartrate = 60000 / (millis() - lastHeartbeatTime);
lastHeartbeatTime = millis();
if (currentHeartrate <= 200)// && currentHeartrate > 20)
{
Wire.println("Heart Rate =" + String(currentHeartrate) + " ");
// delay(100);
}
if (currentHeartrate <= 39 and currentHeartrate >= 0){
Wire.println("I Am Sick");
}
// delay(100);
if (currentHeartrate<= 79 and currentHeartrate >= 70){
Wire.println("Night Mare");
}
// delay(100);
if (currentHeartrate <= 69 and currentHeartrate >= 40){
Wire.println("kid Is At Sleep");
}
//delay(100);
if (currentHeartrate <= 99 and currentHeartrate >= 80){
Wire.println("Kid Is Resting");
}
//delay(100);
if (currentHeartrate <= 119 and currentHeartrate >= 100){
Wire.println("Kid Is Playing");
}
if(currentHeartrate > 120){
Wire.println(" The Kid Is Having ");
//lcd.setCursor(0,1);
//lcd.println(" A Heart Attack");
}
Wire.endTransmission(); // stop transmitting*/
Wire.beginTransmission(4); // transmit to device #4
byte a;
if ( GPS.available() > 0 ) // if there is data coming from the GPS shield
{
a = GPS.read(); // get the byte of data
if(shield.encode(a)) // if there is valid GPS data...
{
getgps(shield); // then grab the data and display it on the LCD
}
float latitude, longitude;
// Then call this function
shield.f_get_position(&latitude, &longitude);
Wire.println("Lat: ");
Wire.println(latitude,5);
Wire.println(" ");
Wire.println("Long: ");
Wire.println(longitude,5);
Wire.println(" ");
}
Wire.endTransmission(); // stop transmitting
Wire.beginTransmission(4); // transmit to device #4
char key = keypad.getKey(); //This calls the keypad its self
if (key) {
Wire.println(key); //This will print which ever key is pressed
}
// int phrase;
//int loca=0;
//{
// for(i =1; i < 4; i++)
// {
//SayPhrase(i);
//delay(1000); // Wait 1 secounds
// }
switch (key) // Switching the keypad numbers to a message
{
case '1': //This calls keypad number 1
// lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
Wire.println("I AM Sick"); //This will display the message
break; //Ends witch for PRESSED
case '2': //This calls keypad number 2
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); ////This set the cursor on line 1 on the LCD screen
Wire.println("I Want Food"); //This will display the message
break; //Ends witch for PRESSED
case '3': //This calls keypad number 3
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
Wire.println("I Am Cold"); //This will display the message
break; //Ends witch for PRESSED
case '4': //This calls keypad number 4
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
Wire.println("RECCA"); //This will display the message
break; //Ends witch for PRESSED
case '5': ////This calls keypad number 5
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
Wire.println("REVON"); //This will display the message
break; //Ends witch for PRESSED
case '6': ////This calls keypad number 6
//lcd.clear(); ////This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
Wire.println("JEAN PAUL"); //This will display the message
break; //Ends witch for PRESSED
case '7': ////This calls keypad number 7
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); ////This set the cursor on line 1 on the LCD screen
Wire.println("MONIA"); //This will display the message
break; //Ends witch for PRESSED
case '8': ////This calls keypad number 8
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
Wire.println("DREAD HAIR"); //This will display the message
break; //Ends witch for PRESSED
}
}
Wire.endTransmission(); // stop transmitting
delay(2000);
}
}
receiver code
//Reciever
#include<SPI.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include<VoiceShield.h>
LiquidCrystal lcd(30,31,32,33,34,35);
//#include <Keypad.h>
int key;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
/*char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
//byte rowPins[ROWS] = {38, 39, 40, 41}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
//byte colPins[COLS] = {42, 43, 44}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );*/
byte ledPin = 13;
VoiceShield vs(80); // Create a instance of the Voice Shield called "vs" with 80 sound slots
int i = 1;
int Sentence[16];
int Phs1[] = {
33, 78, 72, 255}; // "I am cold"
int Phs2[] = {
33, 78, 16}; // "I am sick"
int Phs3[] = {
33, 44, 69}; // "I want food"
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
lcd.begin(16,2);
}
void loop()
{//char key = keypad.getKey(); //This calls the keypad its self
if (key) {
Wire.println(key); //This will print which ever key is pressed
}
int phrase;
int loca=0;
{
for(i =1; i < 4; i++)
{
//SayPhrase(i);
// delay(1000); // Wait 1 secounds
}
switch (key) // Switching the keypad numbers to a message
{
case '1': //This calls keypad number 1
// lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
// Wire.println("I AM Sick"); //This will display the message
for(loca =0; loca < (sizeof(Phs2)/sizeof(int)); loca++)
{
Sentence[loca] = Phs2[loca];
}
break; //Ends witch for PRESSED
case '2': //This calls keypad number 2
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); ////This set the cursor on line 1 on the LCD screen
//Wire.println("I Want Food"); //This will display the message
for(loca =0; loca < (sizeof(Phs3)/sizeof(int)); loca++)
{
Sentence[loca] = Phs3[loca];
}
break; //Ends witch for PRESSED
case '3': //This calls keypad number 3
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
//Wire.println("I Am Cold"); //This will display the message
for(loca =0; loca < (sizeof(Phs1)/sizeof(int)); loca++)
{
Sentence[loca] = Phs1[loca];
}
break; //Ends witch for PRESSED
// case '4': //This calls keypad number 4
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
// Wire.println("RECCA"); //This will display the message
// break; //Ends witch for PRESSED
// case '5': ////This calls keypad number 5
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
// Wire.println("REVON"); //This will display the message
// break; //Ends witch for PRESSED
// case '6': ////This calls keypad number 6
//lcd.clear(); ////This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
// Wire.println("JEAN PAUL"); //This will display the message
// break; //Ends witch for PRESSED
// case '7': ////This calls keypad number 7
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); ////This set the cursor on line 1 on the LCD screen
// Wire.println("MONIA"); //This will display the message
// break; //Ends witch for PRESSED
// case '8': ////This calls keypad number 8
//lcd.clear(); //This clears previous message on the screen
//lcd.setCursor(0,1); //This set the cursor on line 1 on the LCD screen
// Wire.println("DREAD HAIR"); //This will display the message
// break; //Ends witch for PRESSED
default:
Sentence[0] = 255;
}
for(loca=0; loca < 15; loca = loca +1)
{
if(Sentence[loca] == 255)
{
loca = 15;
}
else
{
vs.ISDPLAY_to_EOM(Sentence[loca]);
}
}
}
// Wire.endTransmission(); // stop transmitting
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
delay(20);
}
}
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
//Serial.print(c); // print the character
lcd.setCursor(1,0);
lcd.print(c);
}
int x = Wire.read(); // receive byte as an integer
//Serial.print(x);
lcd.setCursor(0,1);
lcd.print(x);
}
pls i would really appreciate any help.