#include #include "AmbuBag.h" /***** Purpose: a constructor of the setInput class to read the controls and map the inputs Parameters: void Return value: void *****/ setInputs::setInputs(void){ tidalVolume=analogRead(TidalVolume); tidalVolume=map(tidalVolume,0,1023,0,100); breathPerMinute=analogRead(RespiratoryRate); breathPerMinute=map(breathPerMinute,0,1023,10,40); ieRatio=analogRead(IEratio); ieRatio=map(ieRatio,0,1023,1.0,11.0); lcd.setCursor(7,0); lcd.print("I/E="); lcd.print(ieRatio/10.0); lcd.setCursor(0,1); lcd.print("TV="); lcd.print(tidalVolume); lcd.print("% "); lcd.setCursor(9,1); lcd.print("RR="); lcd.print(breathPerMinute); lcd.print("/m"); } /***** Purpose: calculate the inputs to get a valid data to control the inputs Parameters: void Return value: void *****/ void setInputs:: controlsCalculation(){ totalTime= 60.0/breathPerMinute; inhaleTime= totalTime/(1+(ieRatio/10)); exhaleTime= totalTime-inhaleTime; //converted to milisecond in order to use it in delay func. inhaleTime *=1000; exhaleTime *=1000; /* //will use it in stage 2 when mapping the tidalVolume to the motor encoder inputs inhaleFlowRate= tidalVolume/(inhaleTime); exhaleFlowRate= tidalVolume/(exhaleTime); */ //for monitor the data and the operations Serial.println(totalTime); Serial.println(inhaleTime); Serial.println(exhaleTime); //Serial.println(inhaleFlowRate); //Serial.println(exhaleFlowRate); } void inhalePhase (setInputs *parameters) { Serial.println("InhalePhase"); analogWrite(MotorDrivePwm,70); digitalWrite(MotorDriveDir,LOW); delay ((parameters->inhaleTime)); } /***** Purpose: Stop the motor for pause time in the end of the inhale and exhale phase Parameters: void Return value: void *****/ void pausePhase (void) { //for monitor the data and the operations Serial.println("PausePhase"); //Motor control const float pauseTime=0.15; analogWrite(MotorDrivePwm,0); delay (pauseTime*1000); } void exhalePhase (setInputs *parameters) { Serial.println("exhalePhase"); analogWrite(MotorDrivePwm,70); digitalWrite(MotorDriveDir,HIGH); delay ((parameters->exhaleTime)); } void setup(){ //set inputs pins for switch and motor drive pinMode(StartSwitch,INPUT); pinMode(LedPin,OUTPUT); pinMode(MotorDrivePwm,OUTPUT); pinMode(MotorDriveDir,OUTPUT); //LCD lcd.begin(16,2); lcd.setCursor(0,0); lcd.print("Inputs:"); //for monitor the data and the operations Serial.begin(9600); } void loop(){ while(digitalRead(StartSwitch)==LOW){ digitalWrite(LedPin,LOW); setInputs parameters; pausePhase(); } while(digitalRead(StartSwitch)==HIGH){ digitalWrite(LedPin,HIGH); setInputs parameters; parameters.controlsCalculation(); inhalePhase(¶meters); pausePhase(); exhalePhase(¶meters); pausePhase(); } }