[/
void setup()
{
Serial.begin(9600);
noInterrupts(); // disable all interrupts
TCCR3A = 0; //timer interrupt 1seconds//
TCCR3B = 0;
TCNT3 = 0;
OCR3A = 62500; // compare match register 16MHz/256/1Hz
TCCR3B |= (1 << WGM12); // CTC mode
TCCR3B |= (1 << CS12); // 256 prescaler
TIMSK3 |= (1 << OCIE3A); // enable timer compare interrupt
interrupts(); // enable all interrupts
stepper.setMaxSpeed(1000);
tft.reset();
uint16_t identifier = tft.readID(); // this line is used to detect the Driver ID of the LCD. Here Samsung SD060154 LCD Drvier IC is their
tft.begin(identifier); // this line is used to start the LCD Driver to communicate
tft.setRotation(3);
white_border();
}
ISR(TIMER3_COMPA_vect) // timer compare interrupt service routine
{
value1 = 1;
}
/****************************************************************************************************************************************************************************/
/************************************************************* VOID MAIN LOOP() ******** (STARTS) ***********************************************************************/
/****************************************************************************************************************************************************************************/
void loop()
{
TOTAL_VOL_OF_SYRINGE=20;
INCH_PER_VOL=0.123;
VOL_TO_INFUSE=1;
FLOWRATE=60;
finalpage1(); //display data value//
logic = true;
while (logic)
{
key = keypad.waitForKey();
Serial.print(key);
if (key == 'A')
{
logic = false;
}
}
clr_rounded_scrn();
finalpage2();
stepper_run();
}
/****************************************************************************************************************************************************************************/
/************************************************ enter_total_vol_of_syringe_screen() *************************************************************************************/
/****************************************************************************************************************************************************************************/
unsigned long finalpage1()
{
tft.fillScreen(BLACK);
tft.drawRoundRect (0 ,0 , 320, 40 ,10 , WHITE); // screen rectangle
tft.drawRoundRect (0 ,39 , 320, 40 ,10 , WHITE); // screen rectangle
tft.drawRoundRect (0 ,78 , 320, 40 ,10 , WHITE); // screen rectangle
tft.drawRoundRect (0 ,117 , 320, 41 ,10 , WHITE); // screen rectangle
tft.drawRoundRect (0 ,157 , 320, 42 ,10 , WHITE); // screen rectangle
tft.drawRoundRect (0 ,198 , 320, 42 ,10 , WHITE); // screen rectangle
/********************************** Screen Text **************************************/
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.setCursor(90, 15);
tft.print("DATA ENTERED");
tft.setTextSize(1);
tft.setCursor(5, 55);
tft.print("Total Syringe Volume (mL):");
tft.setCursor(5, 95);
tft.println("Inch per Volume (inch/mL):");
tft.setCursor(5,133);
tft.print("Volume to Dispense (mL):");
tft.setCursor (5, 175);
tft.print("Flow Rate (mL/hr):");
tft.setCursor (5, 215);
tft.print("Drug:");
/*********************** Inputs from Variables *********************************/
tft.setTextSize(3); tft.setTextColor(CYAN);
tft.setCursor(180, 48);
tft.println(TOTAL_VOL_OF_SYRINGE);
tft.setCursor(180, 87);
tft.print(INCH_PER_VOL,4);
tft.setCursor(180, 126);
tft.println(VOL_TO_INFUSE,1);
tft.setCursor(180, 167);
tft.println(FLOWRATE,2);
}
unsigned long finalpage2()
{
tft.drawRoundRect (0 ,0 , 320, 40 ,10 , CYAN); // screen rectangle
tft.drawRoundRect (0 ,39 , 200, 40 ,10 , CYAN); // screen rectangle
tft.drawRoundRect (199 ,39 , 121, 40 ,10 , CYAN); // screen rectangle
tft.drawRoundRect (0 ,78 , 241, 40 ,10 , CYAN); // screen rectangle
tft.drawRoundRect (240 ,78 , 80, 40 ,10 , CYAN); // screen rectangle
tft.drawRoundRect (0 ,117 , 320, 41 ,10 , CYAN); // screen rectangle
tft.drawRoundRect (0 ,157 , 320, 42 ,10 , CYAN); // screen rectangle
tft.drawRoundRect (0 ,198 , 320, 42 ,10 , CYAN); // screen rectangle
/********************************** Screen Text **************************************/
tft.setTextSize(1);
tft.setCursor(5, 55);
tft.print("Rate:");
tft.setTextSize(2);
tft.setCursor(230, 52);
tft.println("mL/hr");
tft.setTextSize(1);
tft.setCursor(5, 95);
tft.println("Volume to Infuse:");
tft.setTextSize(2);
tft.setCursor(270, 90);
tft.print("mL");
tft.setCursor(250,170);
tft.print("mL");
tft.setTextSize(1);
tft.setCursor(5,175);
tft.print("Volume Remaining:");
tft.setCursor (5, 133);
tft.print("Time Remaining:");
tft.setCursor (5, 215);
tft.print("Drug:");
tft.setCursor(110, 125);
tft.setTextSize(3);tft.setTextColor(WHITE);
tft.print(" h m s");
tft.setTextSize(3); tft.setTextColor(GREEN);
tft.setCursor(140, 87);
tft.println(VOL_TO_INFUSE, 1);
tft.setTextSize(3);
tft.setCursor(70, 48);
tft.println(FLOWRATE);
tft.setCursor (100, 210);
tft.print("Antracin");
}
//motor function//
unsigned long stepper_run()
{
STEPSIZE = M;
STEPS_PER_mL = (TURNS_PER_INCH * INCH_PER_VOL * 3200);
TARGETSTEPS = (STEPS_PER_mL * VOL_TO_INFUSE);
MOTOR_SPEED = ((STEPS_PER_mL * FLOWRATE) / 3600);
total_time_in_secs = (TARGETSTEPS / MOTOR_SPEED);
logic = true;
value2=1;
while (logic)
{
stepper.moveTo(TARGETSTEPS);
stepper.setSpeed(MOTOR_SPEED);
stepper.runSpeedToPosition();
if (stepper.currentPosition() == TARGETSTEPS)
{
motor.release();
break;
}
time_remaining();
}
}
//UPDATE LCD//
unsigned long time_remaining()
{
if (value1 == 1 && value2==1)
{
total_time_in_secs--;
hours = total_time_in_secs / 3600;
minutes = ((total_time_in_secs % 3600) / 60);
seconds = ((total_time_in_secs % 3600) % 60);
double Volv = (FLOWRATE*total_time_in_secs)/3600; //decremented vol
tft.setTextSize(1);
tft.setTextColor(WHITE);
tft.setCursor (5, 133);
tft.print("Time Remaining");
tft.setCursor(5,175);
tft.print("Volume Infused:");
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.setCursor(120, 127); tft.print (hours);tft.setCursor(170,127); //time_remaing on nrml_operation
tft.print (":");
tft.setCursor(185, 127); tft.print (minutes);tft.setCursor(218,127);
tft.print (":");
tft.setCursor(235, 127); tft.print (seconds);
Serial.print("vol");Serial.println(Volv);
tft.setTextSize(3);
tft.setTextColor(GREEN);
tft.setCursor(135,167);
tft.print(Volv);
tft.fillRoundRect (90, 127, 200, 30, 20, BLACK);
tft.fillRoundRect (115, 167, 130, 30, 25, BLACK);
tft.fillRoundRect (2, 120, 200, 30, 20, BLACK);
tft.fillRoundRect (2, 165, 200, 30, 35, BLACK);
if(total_time_in_secs==0)
{
value2 = 0;
}
value1=0;
}
}
unsigned long clr_rounded_scrn()
{
tft.fillRoundRect(6, 7, 307, 226, 20, BLACK); // this line is for Cleaning the above execution on screen
}
unsigned long white_border()
{
tft.fillScreen(BLACK);
tft.fillRoundRect (0, 0, 320, 240, 20, WHITE);
clr_rounded_scrn();
}
]