#include <glcd.h>
#include <glcd_Buildinfo.h>
#include <glcd_Config.h>
// Reading Heart beating
// Digital Stethoscope Project
// Monash Final Year Project
// Present by
// Karl Wei
// Ce Wang
// Haoxiang Deng
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by providing the nuber of pins to it
LiquidCrystal lcd(8,9,4,5,6,7);
unsigned long previousMillis = 0;
const long interval = 5;
int analog_in0 = A0; // Define an integer which is the output from the microphone 1 in to arduino
int analog_in1 = A1; // Define an integer which is the output from the microphone 2 in to arduino
int sample_points = 0; // Define the interger for the initialised sampling points that we going to take
int led_green = 8;
int led_red = 7;
void setup() // Code for run once:
{
// lcd.begin(16,2);
// set cursor position to start of first line on the LCD
// lcd.setCursor(0,0);
//text to print
// lcd.print(" 16x2 LCD");
// set cusor position to start of next line
//lcd.setCursor(0,1);
//lcd.print(" DISPLAY");
pinMode(analog_in0,INPUT); // set the pin as input, since the sound will be collect from the microphone 1 in to arduino
pinMode(analog_in1,INPUT); // set the pin as input, since the sound will be collect from the microphone 2 in to arduino
pinMode(led_green,OUTPUT);
pinMode(led_red,OUTPUT);
Serial.begin(250000); // allows us to listen to serial communications from the arduino
delay(2000); // wait for 3 second until the arduino to start, this is the time for wating for matlab start to run
}
void loop() // Code for run repeately
{
while ( sample_points < 1000){
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
digitalWrite(led_green,HIGH);
Serial.println(analogRead(A0) - 575);
sample_points++; // everytime there is 1 data, increase sampling points by 1 until it reaches the maxmium which defined above
}
}
digitalWrite(led_red,HIGH);
digitalWrite(led_green,LOW);
}
is this correct now?
in the matlab, it opens the arduino port and reads the data from the serial.print window, and keep it open until it finishes all the reading.