i am having issues getting my code to display the reading from the sensors on the lcd which is located on the second arduino
this is the code that i wrote for it and any help would be great in getting it to work.
//reciever
#include <SPI.h>
#include <LiquidCrystal.h>
int heartratepin=A1;
int inpin=A0;
LiquidCrystal lcd(30,31,32,33,34,35);
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
}
void loop()
{
if(Serial.available()==1)
{
int inByte=Serial.read();
int analogValue=analogRead(inpin);
lcd.print(analogValue);
lcd.print(",");
int newHeartReading=analogRead(heartratepin);
lcd.print(newHeartReading);
lcd.print(",");
}
}
//sender
int inpin=A0;
int TEMP=0;
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;
// Heart rate timing
long lastHeartbeatTime = 0;
long debounceDelay = 150; // the debounce time; increase if the output flickers
int currentHeartrate = 0;
int lastHeartrate = 0;
//Heart rate LED
int ledState = LOW;
long ledOnMillis = 0;
long ledOnInterval = 50;
int slope = ((newHeartReading-lastHeartReading)/(debounceDelay-lastHeartrate));
// Debugging string
String debugOutput = "";
void setup() {
// start serial port at 9600 bps:
Serial.begin(9600);
// pinMode(heartratepin,INPUT);
establishContact();
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println("hello"); // send a starting message
delay(300);
}
}
void loop() {
int analogValue = analogRead(inpin);
float millivolts = (analogValue/1024.0)*5000;
float celsius = millivolts/10-50;
Serial.println(analogValue);
Serial.print(celsius);
Serial.print("c");
Serial.print((celsius*9)/5+32);
Serial.print("F");
newHeartReading = analogRead(heartratepin);
//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;
Serial.println(average);
delay(10);
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
//digitalWrite(ledPin, HIGH);
currentHeartrate = 60000 / (millis() - lastHeartbeatTime);
lastHeartbeatTime = millis();
Serial.println(newHeartReading);
if (currentHeartrate <= 200)// && currentHeartrate > 20)
{
Serial.print("Heart Rate =" + String(currentHeartrate) + " ");
delay(10);
}
if (currentHeartrate <= 39 and currentHeartrate >= 0){
Serial.print("I Am Sick");
}
delay(10);
if (currentHeartrate<= 79 and currentHeartrate >= 70){
Serial.print("Night Mare");
}
delay(10);
if (currentHeartrate <= 69 and currentHeartrate >= 40){
Serial.print("kid Is At Sleep");
}
delay(10);
if (currentHeartrate <= 99 and currentHeartrate >= 80){
Serial.print("Kid Is Resting");
}
delay(10);
if (currentHeartrate <= 119 and currentHeartrate >= 100){
Serial.print("Kid Is Playing");
}
if(currentHeartrate > 120){
Serial.print(" The Kid Is Having ");
Serial.print(" A Heart Attack");
}
// print different formats:
Serial.write(analogValue); // Print the raw binary value
Serial.print('\t'); // print a tab
Serial.write(newHeartReading); // Print the raw binary value
Serial.print('\t'); // print a tab
}
}
}