mahdihir
Published

Medical Adhesive Tape Test

To measure the adhesion of medical adhesive tape. in order to find how change row material in adhesive tape factory.

ExpertWork in progress881
Medical Adhesive Tape Test

Things used in this project

Hardware components

Nextion NX8048T070 - Generic 7.0" HMI TFT LCD Touch Display
Itead Nextion NX8048T070 - Generic 7.0" HMI TFT LCD Touch Display
×1
Analog joystick (Generic)
×1
NEMA 17 Stepper Motor
OpenBuilds NEMA 17 Stepper Motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

02_sBdSVgNIak.jpg

06_ccGet7s3ps.jpg

01_Rb97dPSBxA.jpg

02_Gu5tr5pXHS.jpg

05_WQVB5TrWIS.jpg

Code

MATT.ino

Arduino
r// ***In the name of allah***//
//this program is written by Mahdi Hajy Alimohamadi for MATT machin. its inclouded all function for load cell, thermal printer, joystic , TFT LCD//
//date of last freamware  02/2017
#include "Adafruit_Thermal.h"
Adafruit_Thermal printer(&Serial2);
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
#include <SD.h>
#include <SPI.h>
#include "HX711.h"
#define calibration_factor -7050.0 
#define SD_CS 10
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
  // Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
 #define DOUT  22
#define CLK  23
HX711 scale(DOUT, CLK);
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
int down= 39;
int up = 38;
int senup = 51;
int senmid = 52;
int sendown = 53;
int joystic = A15;
int bott = 26;
 float kilo = 0;
 float avr =0;
 float maxi=0;
 float sum=0;
 int counter=0;
const int f1 = 50;
const int f2 = 49;
const int f3 = 48;
const int f4 = 47;
const int f5 = 46;
const int f6 = 45;
const int startkey = 44;
const int stopkey = 43;
const int printkey = 42;
const int stor = 41;
const int resetkey = 40;

void setup(void)
{



   Serial2.begin(9600);
//scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare();
 // SDFP540 (0x9341)
  
 tft.begin(0x9341);
  
   pinMode (bott, INPUT_PULLUP);
  pinMode(down, OUTPUT);
  pinMode(up, OUTPUT);
  pinMode(senup, INPUT); 
  pinMode(senmid, INPUT);
  pinMode(sendown, INPUT); 
  pinMode(f1, INPUT_PULLUP); 
  pinMode(f2, INPUT_PULLUP); 
  pinMode(f3, INPUT_PULLUP); 
  pinMode(f4, INPUT_PULLUP); 
  pinMode(f5, INPUT_PULLUP); 
  pinMode(f6, INPUT_PULLUP); 
  pinMode(startkey, INPUT_PULLUP); 
  pinMode(stopkey, INPUT_PULLUP); 
  pinMode(printkey, INPUT_PULLUP); 
  pinMode(resetkey, INPUT_PULLUP); 
  pinMode(stor, INPUT_PULLUP); 
int value = 0;

 /* printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: MANUAL");
  printer.feed(1);
  printer.boldOn();
  printer.println("Ahesive Test : Roller Plate");
  printer.boldOff();
  printer.feed(2);
  printer.setSize('S');
  printer.print("Average Force: ");
  printer.print(avr);
  printer.println("  N");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  N");
printer.feed(1);
  printer.print("Number of samples:");
      printer.println(counter);
  printer.feed(1);
  printer.println("Speed ratio: ");
      printer.println(counter);

  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
  */
  
}
//////////////////////////////////////////////////////////////////////////////1inch square
void mili (void){
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println(" 1 Inch Square Test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait... ");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("The head is going to be set in the     proper position");  

    for(int i=25000; i>1; i--){
  digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
  delayMicroseconds(200);                       
  digitalWrite(down, LOW);    
  delayMicroseconds(200);  
    }
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("1 Inch Square Test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please use a loop of      adhesive tape with length of 25 cm and attach to the moving clamp.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 220);
        tft.println("Press START to start.");  
                       tft.setCursor(10, 250);
        tft.println("Press STOP to cancel.");
while (true){
if (digitalRead (startkey) == LOW){
  tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Test is in progress...");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait to finish the  test.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
    for(int i=2000; i>1; i--){
  digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
  delay(1);                       
  digitalWrite(down, LOW);    
  delay(1);  
    }
    delay(500);
    scale.tare();    

    for(int j=30; j>1; j--){
  kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;
    for(int i=100; i>1; i--){

  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delay(1);                       
  digitalWrite(up, LOW);    
  delay(1);  
    }

}
tft.setRotation(3);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(5, 50);
tft.println("Test Is Finished.");
//tft.setCursor(30, 104);
//tft.setTextColor(WHITE);  tft.setTextSize(2);
//tft.println("Avarege Force:");
//tft.setTextColor(YELLOW);  tft.setTextSize(3);
//tft.setCursor(300,100);
//tft.println(avr);
//tft.setCursor(390, 100);
//tft.println("N");
tft.setCursor(30, 134);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Maximum Force:");
tft.setCursor(300, 130);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(maxi);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 130);
tft.println("  Newton");
tft.setCursor(30, 164);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Number of samples:");
tft.setCursor(300, 160);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(counter);         
tft.setCursor(30, 194);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Speed rate:");
tft.setCursor(300, 190);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println("5 mm/s");
tft.setTextColor(CYAN);  tft.setTextSize(2);
tft.setCursor(5, 260);
tft.println("To print results press PRINT."); 
tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP.");    
        while (1){
if (digitalRead (stopkey) == LOW){
     loop();
}
if (digitalRead (printkey) == LOW){
             tft.reset();

 printer.begin();
  printer.inverseOn();
  printer.justify('C');
  printer.setSize('L');
  printer.println("...MATT...");
  printer.inverseOff();
  printer.setSize('S');
  printer.println("Medical Adhesive Tape Test");
  printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: AUTOMATIC");
  printer.feed(1);
  printer.boldOn();
  printer.println("Adhesive Test: 1Inch Square Test");
  printer.boldOff();
  printer.feed(2);
  printer.setSize('S');
 // printer.print("Average Force: ");
  //printer.print(avr);
  //printer.println("  N");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  Newton");
printer.feed(1);
  printer.print("Number of samples: ");
      printer.println(counter);
  printer.feed(1);
  printer.print("Speed ratio: ");
      printer.println("5 mm/s");

  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
     tft.begin(0x9341);
   tft.setRotation(3);
  loop();
}
}
   
}   
}
}
////////////////////////////////////////////////////////////////////////TERMINATION  
 void terminate (void)  { 
        tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(5, 50);
        tft.println("Test Is Terminated By User");
  tft.setTextColor(WHITE);  tft.setTextSize(2);
       tft.setCursor(5, 150);
        tft.println("To print final result prees PRINT.");
               tft.setCursor(5, 180);
        tft.println("To store final result press STORE.");
                  tft.setTextColor(MAGENTA);  tft.setTextSize(2);
               tft.setCursor(5, 240);
        tft.println("To restart press STOP.");
while (1){
    if (digitalRead (stopkey) == LOW){
     loop();
  }
        delay(1);
}        

}

/////////////////////////////////////////////////////////////////////////////////////////////-180degree
void degree (void){
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println(" 180 Degree Test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait... ");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("The head is going to be set in the     proper position");  

    for(int i=25000; i>1; i--){
  digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
  delayMicroseconds(200);                       
  digitalWrite(down, LOW);    
  delayMicroseconds(200);  
    }
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("180 Degree Test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please use appropret clamp and attache one side the specimen to the moving clamp and attache other side to plate.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 260);
        tft.println("Press START to start.");  
                       tft.setCursor(10, 290);
        tft.println("Press STOP to cancel.");
while (true){
if (digitalRead (startkey) == LOW){
  tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Test is in progress...");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("please wait to finish te test.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);

    scale.tare();    

    for(int j=110; j>1; j--){
  kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;
    for(int i=100; i>1; i--){

  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delay(1);                       
  digitalWrite(up, LOW);    
  delay(1);  
    }

}

tft.setRotation(3);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(5, 50);
tft.println("Test Is Finshed.");
tft.setCursor(30, 104);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Avarege Force:");
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(300,100);
tft.println(avr);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 100);
tft.println(" Newton");
tft.setCursor(30, 134);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Maximum Force:");
tft.setCursor(300, 130);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(maxi);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 130);
tft.println(" Newton");
tft.setCursor(30, 164);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Number of samples:");
tft.setCursor(300, 160);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(counter);         
tft.setCursor(30, 194);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Speed rate:");
tft.setCursor(300, 190);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println("5 mm/s");
tft.setTextColor(CYAN);  tft.setTextSize(2);
tft.setCursor(5, 260);
tft.println("To print results press PRINT."); 
tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP.");    
        while (1){
if (digitalRead (stopkey) == LOW){
     loop();
}
if (digitalRead (printkey) == LOW){
             tft.reset();

 printer.begin();
  printer.inverseOn();
  printer.justify('C');
  printer.setSize('L');
  printer.println("...MATT...");
  printer.inverseOff();
  printer.setSize('S');
  printer.println("Medical Adhesive Tape Test");
  printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: AUTOMATIC");
  printer.feed(1);
  printer.boldOn();
  printer.println("Adhesive Test: 180 degree");
  printer.boldOff();
  printer.feed(2);
  printer.setSize('S');
  printer.print("Average Force: ");
  printer.print(avr);
  printer.println("  Newton");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  Newton");
printer.feed(1);
  printer.print("Number of samples: ");
      printer.println(counter);
  printer.feed(1);
  printer.print("Speed ratio: ");
      printer.println("5 mm/s");

  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
     tft.begin(0x9341);
   tft.setRotation(3);
  loop();
}
}


}
}}  

/////////////////////////////////////////////////////////alarm
void alarm (void){
  tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(5, 50);
        tft.println("ALARM!");
  tft.setTextColor(WHITE);  tft.setTextSize(2);
       tft.setCursor(5, 150);
        tft.println("The force is raeched limit       (>40 N)");
               tft.setCursor(5, 180);
        tft.println("Please remove tape ad restart test.");
                  tft.setTextColor(MAGENTA);  tft.setTextSize(2);
               tft.setCursor(5, 240);
        tft.println("To restart press STOP.");
        while(true){
          if (digitalRead (stopkey) == LOW){
terminate();
  
}}}
 ////////////////////////////////////////////////////////////////////////////////////////////////////////MAIN LOOP
void loop(void)
{


//////////////////////////////////////////////////////////////////////////////////////////////////////////Initialaizing  

kilo=0;
maxi=0;
sum=0;
avr=0;
counter=0;

  /////////logo
  tft.setRotation(3);
    tft.fillScreen(WHITE);
    tft.fillScreen(MAGENTA);
    tft.fillScreen(WHITE);
    tft.setTextColor(BLUE);
    tft.setTextSize(7); 
      tft.setCursor(100, 50);
  tft.println("M A T T");
    tft.setTextColor(CYAN);  tft.setTextSize(3); 
      tft.setCursor(5, 150);
  tft.println("Medical Adhesive Tape Test");  
      tft.setTextColor(BLACK);  tft.setTextSize(2); 
      tft.setCursor(20, 230);
  tft.println("Designed and Developed by DNP co."); 
        tft.setCursor(20, 260);
  tft.println("www.DNP-CO.ir"); 
        tft.setCursor(20, 290);
  tft.println("Tel: +98-912 522 1037"); 
  delay(5000); 
///////////////////////

      tft.fillScreen(BLACK);
    tft.setTextColor(WHITE);  tft.setTextSize(1);
  tft.setCursor(10, 10);
  tft.println("Version. 2.6 Sep 2017");
  tft.setTextColor(WHITE);  tft.setTextSize(3);
  tft.setCursor(100, 50);
  tft.println("Initializing...");
  tft.setTextColor(YELLOW);  tft.setTextSize(2);
    tft.setCursor(30, 100);
  tft.println("Self Test:");
    tft.setCursor(30, 120);
  tft.println("Limit Sensors, Motor, ROM, Loadcell ");

    tft.setTextColor(WHITE);  tft.setTextSize(2);
      tft.setCursor(150, 150);
  tft.println("Please wait...");
  
      tft.setTextColor(WHITE);  tft.setTextSize(2);
      tft.setCursor(10, 290);
 tft.println("www.DNP-CO.ir              09125221037");

for (int n=3; n>0; n--){

        tft.setTextColor(YELLOW);  tft.setTextSize(2);
       tft.setCursor(210, 220);  
   tft.println(n);
//    tft.setCursor(210, 240); 
       //   tft.println(kilo);
     delay(1000);
      tft.setTextColor(BLACK);  tft.setTextSize(2);
       tft.setCursor(210, 220);  
   tft.println(n);
    //   tft.setCursor(210, 240); 
    //      tft.println(kilo);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////Auto Position
tft.fillScreen(BLACK);
        tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(50, 50);
         tft.println("Auto Set Postition...");
        tft.setTextColor(WHITE);  tft.setTextSize(2);
       tft.setCursor(5, 100);
         tft.println("Please wait while the haed is going to    be set in the zero position.");

               tft.setTextColor(WHITE);  tft.setTextSize(2);
      tft.setCursor(10, 270);
  tft.println("www.DNP-CO.ir              09125221037");
  while (true) 
  {


  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delayMicroseconds(200);                       
  digitalWrite(up, LOW);    
  delayMicroseconds(200); 
      if (digitalRead(senup)== HIGH){
        delay(10);
        if(digitalRead(senup)==HIGH){
      break;
        }
    }  
  }
    
  for (int m=200; m>0; m--){
     digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
delayMicroseconds(200);
digitalWrite(down, LOW);    
delayMicroseconds(200);
  
  }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////Manual / Auto  selection
   tft.fillScreen(BLACK);
        tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
         tft.println("Please select Test Mode: ");
                 tft.setTextColor(WHITE);  tft.setTextSize(3);
         tft.setCursor(5, 130);
 tft.println("For Manual press 1.");
          tft.setCursor(5, 180);
 tft.println("For Auto press 2");
  while (1){
  if (digitalRead(f1) == LOW){
manualmode();
  }
if (digitalRead(f2) == LOW){
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Please select the type of test");
tft.setTextColor(WHITE);  tft.setTextSize(2);

               tft.setCursor(10, 200);
        tft.println("For Tension Test press F1.");  
                       tft.setCursor(10, 230);
        tft.println("For Adhesive Test press F2.");
  while (1){
  if (digitalRead(f1) == LOW){
tension();
  }
    if (digitalRead(f2) == LOW){
      
       tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Adhesie test selection:");
tft.setTextColor(WHITE);  tft.setTextSize(2);
              tft.setCursor(10, 150);
        tft.println("Roller Plate = F1");  
                       tft.setCursor(10, 180);
        tft.println("1 Inch Square= F2.");
tft.setCursor(10, 210);
        tft.println("180 degree test = F3.");
        tft.setTextColor(MAGENTA);
 tft.setCursor(10, 270);
        tft.println("To cancel press STOP.");       

while (true){
    if (digitalRead(f1) == LOW){
      rollerplate();
      
    }
        if (digitalRead(f2) == LOW){

mili();
    }
        if (digitalRead(f3) == LOW){
degree();
}
        if (digitalRead(stopkey) == LOW){
terminate();
}
}
}
}  
}
}
tft.fillScreen(BLACK);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////TENSION
  void tension (void){
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Tension test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait... ");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("The head is going to be set in the       proper position.");  

  while (digitalRead(sendown) == LOW) 
  {

  digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
delayMicroseconds(200);
digitalWrite(down, LOW);    
delayMicroseconds(200);
}
    for (int m=1000; m>0; m--){
     digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
delayMicroseconds(200);
digitalWrite(up, LOW);    
delayMicroseconds(200);
  
  }
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Tension test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please attache appropriateclamp according to the    width of tape.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("Press START to start.");  
                       tft.setCursor(10, 230);
        tft.println("Press STOP to cancel.");

while (true){
    if (digitalRead (startkey) == LOW){
     break;}
    if (digitalRead (stopkey) == LOW){

terminate();} 
  
}
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Test is in progress...");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("please wait to finish the test.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);

        tft.println("Press STOP to cancel.");
    scale.tare();  
    for (int i=0; i<1000 ; i++){
  if (digitalRead(senmid)== HIGH)break;
  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delay(1);                       
  digitalWrite(up, LOW);    
  delay(1);  
  }  
 while (digitalRead(senmid) == LOW) 
  {
    
  kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;

if (digitalRead (stopkey) == LOW){
//.......................................................................................................................................................................................
terminate();}
for (int i=0; i<500 ; i++){
  if (digitalRead(senmid)== HIGH)break;
  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delay(1);                       
  digitalWrite(up, LOW);    
  delay(1);  
  }
  if(kilo < avr)break;
  } 
////////////////////////result show
tft.setRotation(3);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(5, 50);
tft.println("Test Is Finshed.");
//tft.setCursor(30, 104);
//tft.setTextColor(WHITE);  tft.setTextSize(2);
//tft.println("Avarege Force:");
//tft.setTextColor(YELLOW);  tft.setTextSize(2);
//tft.setCursor(300,100);
//tft.println(avr);
//tft.setCursor(390, 100);
//tft.println("Newton");
tft.setCursor(30, 134);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Maximum Force:");
tft.setCursor(300, 130);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(maxi);
tft.setTextColor(YELLOW);  tft.setTextSize(2);
tft.setCursor(390, 130);
tft.println(" Newton");
tft.setCursor(30, 164);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Number of samples:");
tft.setCursor(300, 160);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(counter);         
tft.setCursor(30, 194);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Speed rate:");
tft.setCursor(300, 190);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println("5 mm/s");
tft.setTextColor(CYAN);  tft.setTextSize(2);
tft.setCursor(5, 260);
tft.println("To print results press PRINT."); 
tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP.");    
        while (1){
if (digitalRead (stopkey) == LOW){
     loop();
}
if (digitalRead (printkey) == LOW){
        tft.reset();

 printer.begin();
  printer.inverseOn();
  printer.justify('C');
  printer.setSize('L');
  printer.println("...MATT...");
  printer.inverseOff();
  printer.setSize('S');
  printer.println("Medical Adhesive Tape Test");
  printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: AUTOMATIC");
  printer.feed(1);
  printer.boldOn();
  printer.println("Tension Test");
  printer.boldOff();
  printer.feed(3);
 // printer.setSize('S');
 // printer.print("Average Force: ");
 // printer.print(avr);
 // printer.println("  N");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  Newton");
printer.feed(1);
  printer.print("Number of samples: ");
      printer.println(counter);
  printer.feed(1);
  printer.print("Speed ratio: ");
      printer.println("5 mm/s");

  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
     tft.begin(0x9341);
   tft.setRotation(3);
  loop();
}
} /////////////////////////////////////
  }
 ////////////////////////////////////////////////////////////////////////////////ROLLER PLATE
void rollerplate (void){
  tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Roller Plate Test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait... ");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("The head is going to be set in the       proper position");  
  while (digitalRead(sendown) == LOW) 
  {
  digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
delayMicroseconds(200);
digitalWrite(down, LOW);    
delayMicroseconds(200);
}
      for (int m=500; m>0; m--){
     digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
delayMicroseconds(200);
digitalWrite(up, LOW);    
delayMicroseconds(200);
  
  }
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Tension test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 105);
        tft.println("Please attache             Roller Plate. ");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("Press START to start.");  
                       tft.setCursor(10, 230);
        tft.println("Press STOP to cancel.");
while (true){
if (digitalRead (startkey) == LOW){
break;
  }
  if (digitalRead (stopkey) == LOW){
terminate();
  }
}
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Test is in progress...");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait to finish the test.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);

        tft.println("Press STOP to cancel.");
   scale.tare();   
         
 while (digitalRead(senmid) == LOW) 
  {
    while (digitalRead(senmid) == LOW) {
  kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;
for (int i=0; i<100 ; i++){
  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delay(1);                       
  digitalWrite(up, LOW);    
  delay(1); 
  digitalWrite (stopkey, HIGH);
  int key =0;
  key = digitalRead (stopkey);
   if (key == LOW) {

  terminate(); }
  }}

  }
      for (int m=500; m>0; m--){
     digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
  delay(1);                       
  digitalWrite(down, LOW);    
  delay(1);  
  
  }

  
   tft.setRotation(3);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(5, 50);
tft.println("Test Is Finshed.");
tft.setCursor(30, 104);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Avarege Force:");
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(300,100);
tft.println(avr);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 100);
tft.println(" Newton");
tft.setCursor(30, 134);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Maximum Force:");
tft.setCursor(300, 130);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(maxi);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 130);
tft.println(" Newton");
tft.setCursor(30, 164);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Number of samples:");
tft.setCursor(300, 160);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(counter);         
tft.setCursor(30, 194);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Speed rate:");
tft.setCursor(300, 190);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println("5 mm/s");
tft.setTextColor(CYAN);  tft.setTextSize(2);
tft.setCursor(5, 260);
tft.println("To print results press PRINT."); 
tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP.");     
        while (1){
if (digitalRead (stopkey) == LOW){
  tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(4);
tft.setCursor(5, 50);
tft.println("WARRNING!!!");
tft.setCursor(30, 104);
tft.setTextColor(WHITE);  tft.setTextSize(3);
tft.println("Remove plate's cable      from the head.");
tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP."); 
while(true){
if (digitalRead (stopkey) == LOW){
     loop();}}
}
if (digitalRead (printkey) == LOW){
             tft.reset();

 printer.begin();
  printer.inverseOn();
  printer.justify('C');
  printer.setSize('L');
  printer.println("...MATT...");
  printer.inverseOff();
  printer.setSize('S');
  printer.println("Medical Adhesive Tape Test");
  printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: AUTOMATIC");
  printer.feed(1);
  printer.boldOn();
  printer.println("Adhesive Test: Roller Plate");
  printer.boldOff();
  printer.feed(2);
  printer.setSize('S');
  printer.print("Average Force: ");
  printer.print(avr);
  printer.println("  Newton");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  Newton");
printer.feed(1);
  printer.print("Number of samples: ");
      printer.println(counter);
  printer.feed(1);
  printer.print("Speed ratio: ");
      printer.println("5 mm/s");

  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
     tft.begin(0x9341);
   tft.setRotation(3);

     tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(4);
tft.setCursor(5, 50);
tft.println("WARRNING!!!");
tft.setCursor(30, 104);
tft.setTextColor(WHITE);  tft.setTextSize(3);
tft.println("Remove plate's cable      from the head.");

tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP."); 
while(true){
if (digitalRead (stopkey) == LOW){
  loop();}}
}
}    
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////MANUAL MODE
 void manualmode (void)
 {

 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Manual Mode is selected");
tft.setTextColor(WHITE);  tft.setTextSize(2);
       tft.setCursor(10, 150);
        tft.println("Press START to continiu.");
               tft.setCursor(10, 200);
        tft.println("Press STOP to cancel.");
         while (1){
    if (digitalRead (startkey) == LOW){
    goto manual;
  }
    if (digitalRead (stopkey) == LOW){
  terminate();
  }
  }
    manual:  
  /////////////////////////////////////////////////////////////////////////////////////////////////////////joystick
  kilo=0;
  maxi=0;
  counter=0;
  avr=0;
maxi=0;
sum=0;
int value =0;
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(2);
       tft.setCursor(5, 50);
        tft.println("Use Joystick to move head up and down.");  
               tft.setCursor(5, 100);
        tft.println(""); 
                       tft.setCursor(5, 150);
        tft.println("To finish test press STOP.");   
    tft.setTextColor(WHITE);  tft.setTextSize(4);

scale.tare();  
while(true)
 {
 delay(500);
  value = analogRead(joystic);
    value = value/100; 
    if (digitalRead (stopkey) == LOW){
     break;
    }/*//////
      kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;
    *///////

   while (value>7){
for(int i=200; i>1; i--){
  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
delayMicroseconds(700);
digitalWrite(up, LOW);    
delayMicroseconds(700);
}
  kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;
  value = analogRead(joystic);
    value = value/100; 
  }

  while( value<3){

     digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
delayMicroseconds(200);
digitalWrite(down, LOW);    
delayMicroseconds(200);
value = analogRead(joystic);
    value = value/100;
  }
}
tft.setRotation(3);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(5, 50);
tft.println("Test Is Finshed.");
tft.setCursor(30, 104);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Avarege Force:");
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(300,100);
tft.println(avr);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 100);
tft.println(" Newton");
tft.setCursor(30, 134);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Maximum Force:");
tft.setCursor(300, 130);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(maxi);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 130);
tft.println(" Newton");
tft.setCursor(30, 164);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Number of samples:");
tft.setCursor(300, 160);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(counter);         
     

tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 260);
tft.println("To restart press STOP.");     
        while (1){
if (digitalRead (stopkey) == LOW){
    goto manual;
}
if (digitalRead (resetkey) == LOW){
    loop();
}
if (digitalRead (printkey) == LOW){
             tft.reset();

 printer.begin();
  printer.inverseOn();
  printer.justify('C');
  printer.setSize('L');
  printer.println("...MATT...");
  printer.inverseOff();
  printer.setSize('S');
  printer.println("Medical Adhesive Tape Test");
  printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: MANUAL");
  printer.feed(1);
  printer.boldOn();
  printer.println("Tension Test");
   printer.boldOff();
  printer.feed(2);
  printer.setSize('S');
  printer.print("Average Force: ");
  printer.print(avr);
  printer.println("  Newton");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  Newton");
printer.feed(1);
  printer.print("Number of samples: ");
  
  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
     tft.begin(0x9341);
   tft.setRotation(3);
  goto manual;

}
}  

 } 

MATT.ino

Arduino
r// ***In the name of allah***//
//this program is written by Mahdi Hajy Alimohamadi for MATT machin. its inclouded all function for load cell, thermal printer, joystic , TFT LCD//
//date of last freamware  02/2017
#include "Adafruit_Thermal.h"
Adafruit_Thermal printer(&Serial2);
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
#include <SD.h>
#include <SPI.h>
#include "HX711.h"
#define calibration_factor -7050.0 
#define SD_CS 10
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
  // Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
 #define DOUT  22
#define CLK  23
HX711 scale(DOUT, CLK);
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
int down= 39;
int up = 38;
int senup = 51;
int senmid = 52;
int sendown = 53;
int joystic = A15;
int bott = 26;
 float kilo = 0;
 float avr =0;
 float maxi=0;
 float sum=0;
 int counter=0;
const int f1 = 50;
const int f2 = 49;
const int f3 = 48;
const int f4 = 47;
const int f5 = 46;
const int f6 = 45;
const int startkey = 44;
const int stopkey = 43;
const int printkey = 42;
const int stor = 41;
const int resetkey = 40;

void setup(void)
{



   Serial2.begin(9600);
//scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare();
 // SDFP540 (0x9341)
  
 tft.begin(0x9341);
  
   pinMode (bott, INPUT_PULLUP);
  pinMode(down, OUTPUT);
  pinMode(up, OUTPUT);
  pinMode(senup, INPUT); 
  pinMode(senmid, INPUT);
  pinMode(sendown, INPUT); 
  pinMode(f1, INPUT_PULLUP); 
  pinMode(f2, INPUT_PULLUP); 
  pinMode(f3, INPUT_PULLUP); 
  pinMode(f4, INPUT_PULLUP); 
  pinMode(f5, INPUT_PULLUP); 
  pinMode(f6, INPUT_PULLUP); 
  pinMode(startkey, INPUT_PULLUP); 
  pinMode(stopkey, INPUT_PULLUP); 
  pinMode(printkey, INPUT_PULLUP); 
  pinMode(resetkey, INPUT_PULLUP); 
  pinMode(stor, INPUT_PULLUP); 
int value = 0;

 /* printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: MANUAL");
  printer.feed(1);
  printer.boldOn();
  printer.println("Ahesive Test : Roller Plate");
  printer.boldOff();
  printer.feed(2);
  printer.setSize('S');
  printer.print("Average Force: ");
  printer.print(avr);
  printer.println("  N");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  N");
printer.feed(1);
  printer.print("Number of samples:");
      printer.println(counter);
  printer.feed(1);
  printer.println("Speed ratio: ");
      printer.println(counter);

  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
  */
  
}
//////////////////////////////////////////////////////////////////////////////1inch square
void mili (void){
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println(" 1 Inch Square Test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait... ");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("The head is going to be set in the     proper position");  

    for(int i=25000; i>1; i--){
  digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
  delayMicroseconds(200);                       
  digitalWrite(down, LOW);    
  delayMicroseconds(200);  
    }
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("1 Inch Square Test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please use a loop of      adhesive tape with length of 25 cm and attach to the moving clamp.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 220);
        tft.println("Press START to start.");  
                       tft.setCursor(10, 250);
        tft.println("Press STOP to cancel.");
while (true){
if (digitalRead (startkey) == LOW){
  tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Test is in progress...");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait to finish the  test.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
    for(int i=2000; i>1; i--){
  digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
  delay(1);                       
  digitalWrite(down, LOW);    
  delay(1);  
    }
    delay(500);
    scale.tare();    

    for(int j=30; j>1; j--){
  kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;
    for(int i=100; i>1; i--){

  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delay(1);                       
  digitalWrite(up, LOW);    
  delay(1);  
    }

}
tft.setRotation(3);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(5, 50);
tft.println("Test Is Finished.");
//tft.setCursor(30, 104);
//tft.setTextColor(WHITE);  tft.setTextSize(2);
//tft.println("Avarege Force:");
//tft.setTextColor(YELLOW);  tft.setTextSize(3);
//tft.setCursor(300,100);
//tft.println(avr);
//tft.setCursor(390, 100);
//tft.println("N");
tft.setCursor(30, 134);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Maximum Force:");
tft.setCursor(300, 130);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(maxi);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 130);
tft.println("  Newton");
tft.setCursor(30, 164);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Number of samples:");
tft.setCursor(300, 160);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(counter);         
tft.setCursor(30, 194);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Speed rate:");
tft.setCursor(300, 190);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println("5 mm/s");
tft.setTextColor(CYAN);  tft.setTextSize(2);
tft.setCursor(5, 260);
tft.println("To print results press PRINT."); 
tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP.");    
        while (1){
if (digitalRead (stopkey) == LOW){
     loop();
}
if (digitalRead (printkey) == LOW){
             tft.reset();

 printer.begin();
  printer.inverseOn();
  printer.justify('C');
  printer.setSize('L');
  printer.println("...MATT...");
  printer.inverseOff();
  printer.setSize('S');
  printer.println("Medical Adhesive Tape Test");
  printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: AUTOMATIC");
  printer.feed(1);
  printer.boldOn();
  printer.println("Adhesive Test: 1Inch Square Test");
  printer.boldOff();
  printer.feed(2);
  printer.setSize('S');
 // printer.print("Average Force: ");
  //printer.print(avr);
  //printer.println("  N");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  Newton");
printer.feed(1);
  printer.print("Number of samples: ");
      printer.println(counter);
  printer.feed(1);
  printer.print("Speed ratio: ");
      printer.println("5 mm/s");

  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
     tft.begin(0x9341);
   tft.setRotation(3);
  loop();
}
}
   
}   
}
}
////////////////////////////////////////////////////////////////////////TERMINATION  
 void terminate (void)  { 
        tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(5, 50);
        tft.println("Test Is Terminated By User");
  tft.setTextColor(WHITE);  tft.setTextSize(2);
       tft.setCursor(5, 150);
        tft.println("To print final result prees PRINT.");
               tft.setCursor(5, 180);
        tft.println("To store final result press STORE.");
                  tft.setTextColor(MAGENTA);  tft.setTextSize(2);
               tft.setCursor(5, 240);
        tft.println("To restart press STOP.");
while (1){
    if (digitalRead (stopkey) == LOW){
     loop();
  }
        delay(1);
}        

}

/////////////////////////////////////////////////////////////////////////////////////////////-180degree
void degree (void){
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println(" 180 Degree Test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait... ");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("The head is going to be set in the     proper position");  

    for(int i=25000; i>1; i--){
  digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
  delayMicroseconds(200);                       
  digitalWrite(down, LOW);    
  delayMicroseconds(200);  
    }
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("180 Degree Test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please use appropret clamp and attache one side the specimen to the moving clamp and attache other side to plate.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 260);
        tft.println("Press START to start.");  
                       tft.setCursor(10, 290);
        tft.println("Press STOP to cancel.");
while (true){
if (digitalRead (startkey) == LOW){
  tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Test is in progress...");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("please wait to finish te test.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);

    scale.tare();    

    for(int j=110; j>1; j--){
  kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;
    for(int i=100; i>1; i--){

  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delay(1);                       
  digitalWrite(up, LOW);    
  delay(1);  
    }

}

tft.setRotation(3);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(5, 50);
tft.println("Test Is Finshed.");
tft.setCursor(30, 104);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Avarege Force:");
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(300,100);
tft.println(avr);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 100);
tft.println(" Newton");
tft.setCursor(30, 134);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Maximum Force:");
tft.setCursor(300, 130);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(maxi);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 130);
tft.println(" Newton");
tft.setCursor(30, 164);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Number of samples:");
tft.setCursor(300, 160);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(counter);         
tft.setCursor(30, 194);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Speed rate:");
tft.setCursor(300, 190);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println("5 mm/s");
tft.setTextColor(CYAN);  tft.setTextSize(2);
tft.setCursor(5, 260);
tft.println("To print results press PRINT."); 
tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP.");    
        while (1){
if (digitalRead (stopkey) == LOW){
     loop();
}
if (digitalRead (printkey) == LOW){
             tft.reset();

 printer.begin();
  printer.inverseOn();
  printer.justify('C');
  printer.setSize('L');
  printer.println("...MATT...");
  printer.inverseOff();
  printer.setSize('S');
  printer.println("Medical Adhesive Tape Test");
  printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: AUTOMATIC");
  printer.feed(1);
  printer.boldOn();
  printer.println("Adhesive Test: 180 degree");
  printer.boldOff();
  printer.feed(2);
  printer.setSize('S');
  printer.print("Average Force: ");
  printer.print(avr);
  printer.println("  Newton");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  Newton");
printer.feed(1);
  printer.print("Number of samples: ");
      printer.println(counter);
  printer.feed(1);
  printer.print("Speed ratio: ");
      printer.println("5 mm/s");

  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
     tft.begin(0x9341);
   tft.setRotation(3);
  loop();
}
}


}
}}  

/////////////////////////////////////////////////////////alarm
void alarm (void){
  tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(5, 50);
        tft.println("ALARM!");
  tft.setTextColor(WHITE);  tft.setTextSize(2);
       tft.setCursor(5, 150);
        tft.println("The force is raeched limit       (>40 N)");
               tft.setCursor(5, 180);
        tft.println("Please remove tape ad restart test.");
                  tft.setTextColor(MAGENTA);  tft.setTextSize(2);
               tft.setCursor(5, 240);
        tft.println("To restart press STOP.");
        while(true){
          if (digitalRead (stopkey) == LOW){
terminate();
  
}}}
 ////////////////////////////////////////////////////////////////////////////////////////////////////////MAIN LOOP
void loop(void)
{


//////////////////////////////////////////////////////////////////////////////////////////////////////////Initialaizing  

kilo=0;
maxi=0;
sum=0;
avr=0;
counter=0;

  /////////logo
  tft.setRotation(3);
    tft.fillScreen(WHITE);
    tft.fillScreen(MAGENTA);
    tft.fillScreen(WHITE);
    tft.setTextColor(BLUE);
    tft.setTextSize(7); 
      tft.setCursor(100, 50);
  tft.println("M A T T");
    tft.setTextColor(CYAN);  tft.setTextSize(3); 
      tft.setCursor(5, 150);
  tft.println("Medical Adhesive Tape Test");  
      tft.setTextColor(BLACK);  tft.setTextSize(2); 
      tft.setCursor(20, 230);
  tft.println("Designed and Developed by DNP co."); 
        tft.setCursor(20, 260);
  tft.println("www.DNP-CO.ir"); 
        tft.setCursor(20, 290);
  tft.println("Tel: +98-912 522 1037"); 
  delay(5000); 
///////////////////////

      tft.fillScreen(BLACK);
    tft.setTextColor(WHITE);  tft.setTextSize(1);
  tft.setCursor(10, 10);
  tft.println("Version. 2.6 Sep 2017");
  tft.setTextColor(WHITE);  tft.setTextSize(3);
  tft.setCursor(100, 50);
  tft.println("Initializing...");
  tft.setTextColor(YELLOW);  tft.setTextSize(2);
    tft.setCursor(30, 100);
  tft.println("Self Test:");
    tft.setCursor(30, 120);
  tft.println("Limit Sensors, Motor, ROM, Loadcell ");

    tft.setTextColor(WHITE);  tft.setTextSize(2);
      tft.setCursor(150, 150);
  tft.println("Please wait...");
  
      tft.setTextColor(WHITE);  tft.setTextSize(2);
      tft.setCursor(10, 290);
 tft.println("www.DNP-CO.ir              09125221037");

for (int n=3; n>0; n--){

        tft.setTextColor(YELLOW);  tft.setTextSize(2);
       tft.setCursor(210, 220);  
   tft.println(n);
//    tft.setCursor(210, 240); 
       //   tft.println(kilo);
     delay(1000);
      tft.setTextColor(BLACK);  tft.setTextSize(2);
       tft.setCursor(210, 220);  
   tft.println(n);
    //   tft.setCursor(210, 240); 
    //      tft.println(kilo);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////Auto Position
tft.fillScreen(BLACK);
        tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(50, 50);
         tft.println("Auto Set Postition...");
        tft.setTextColor(WHITE);  tft.setTextSize(2);
       tft.setCursor(5, 100);
         tft.println("Please wait while the haed is going to    be set in the zero position.");

               tft.setTextColor(WHITE);  tft.setTextSize(2);
      tft.setCursor(10, 270);
  tft.println("www.DNP-CO.ir              09125221037");
  while (true) 
  {


  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delayMicroseconds(200);                       
  digitalWrite(up, LOW);    
  delayMicroseconds(200); 
      if (digitalRead(senup)== HIGH){
        delay(10);
        if(digitalRead(senup)==HIGH){
      break;
        }
    }  
  }
    
  for (int m=200; m>0; m--){
     digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
delayMicroseconds(200);
digitalWrite(down, LOW);    
delayMicroseconds(200);
  
  }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////Manual / Auto  selection
   tft.fillScreen(BLACK);
        tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
         tft.println("Please select Test Mode: ");
                 tft.setTextColor(WHITE);  tft.setTextSize(3);
         tft.setCursor(5, 130);
 tft.println("For Manual press 1.");
          tft.setCursor(5, 180);
 tft.println("For Auto press 2");
  while (1){
  if (digitalRead(f1) == LOW){
manualmode();
  }
if (digitalRead(f2) == LOW){
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Please select the type of test");
tft.setTextColor(WHITE);  tft.setTextSize(2);

               tft.setCursor(10, 200);
        tft.println("For Tension Test press F1.");  
                       tft.setCursor(10, 230);
        tft.println("For Adhesive Test press F2.");
  while (1){
  if (digitalRead(f1) == LOW){
tension();
  }
    if (digitalRead(f2) == LOW){
      
       tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Adhesie test selection:");
tft.setTextColor(WHITE);  tft.setTextSize(2);
              tft.setCursor(10, 150);
        tft.println("Roller Plate = F1");  
                       tft.setCursor(10, 180);
        tft.println("1 Inch Square= F2.");
tft.setCursor(10, 210);
        tft.println("180 degree test = F3.");
        tft.setTextColor(MAGENTA);
 tft.setCursor(10, 270);
        tft.println("To cancel press STOP.");       

while (true){
    if (digitalRead(f1) == LOW){
      rollerplate();
      
    }
        if (digitalRead(f2) == LOW){

mili();
    }
        if (digitalRead(f3) == LOW){
degree();
}
        if (digitalRead(stopkey) == LOW){
terminate();
}
}
}
}  
}
}
tft.fillScreen(BLACK);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////TENSION
  void tension (void){
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Tension test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait... ");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("The head is going to be set in the       proper position.");  

  while (digitalRead(sendown) == LOW) 
  {

  digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
delayMicroseconds(200);
digitalWrite(down, LOW);    
delayMicroseconds(200);
}
    for (int m=1000; m>0; m--){
     digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
delayMicroseconds(200);
digitalWrite(up, LOW);    
delayMicroseconds(200);
  
  }
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Tension test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please attache appropriateclamp according to the    width of tape.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("Press START to start.");  
                       tft.setCursor(10, 230);
        tft.println("Press STOP to cancel.");

while (true){
    if (digitalRead (startkey) == LOW){
     break;}
    if (digitalRead (stopkey) == LOW){

terminate();} 
  
}
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Test is in progress...");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("please wait to finish the test.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);

        tft.println("Press STOP to cancel.");
    scale.tare();  
    for (int i=0; i<1000 ; i++){
  if (digitalRead(senmid)== HIGH)break;
  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delay(1);                       
  digitalWrite(up, LOW);    
  delay(1);  
  }  
 while (digitalRead(senmid) == LOW) 
  {
    
  kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;

if (digitalRead (stopkey) == LOW){
//.......................................................................................................................................................................................
terminate();}
for (int i=0; i<500 ; i++){
  if (digitalRead(senmid)== HIGH)break;
  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delay(1);                       
  digitalWrite(up, LOW);    
  delay(1);  
  }
  if(kilo < avr)break;
  } 
////////////////////////result show
tft.setRotation(3);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(5, 50);
tft.println("Test Is Finshed.");
//tft.setCursor(30, 104);
//tft.setTextColor(WHITE);  tft.setTextSize(2);
//tft.println("Avarege Force:");
//tft.setTextColor(YELLOW);  tft.setTextSize(2);
//tft.setCursor(300,100);
//tft.println(avr);
//tft.setCursor(390, 100);
//tft.println("Newton");
tft.setCursor(30, 134);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Maximum Force:");
tft.setCursor(300, 130);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(maxi);
tft.setTextColor(YELLOW);  tft.setTextSize(2);
tft.setCursor(390, 130);
tft.println(" Newton");
tft.setCursor(30, 164);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Number of samples:");
tft.setCursor(300, 160);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(counter);         
tft.setCursor(30, 194);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Speed rate:");
tft.setCursor(300, 190);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println("5 mm/s");
tft.setTextColor(CYAN);  tft.setTextSize(2);
tft.setCursor(5, 260);
tft.println("To print results press PRINT."); 
tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP.");    
        while (1){
if (digitalRead (stopkey) == LOW){
     loop();
}
if (digitalRead (printkey) == LOW){
        tft.reset();

 printer.begin();
  printer.inverseOn();
  printer.justify('C');
  printer.setSize('L');
  printer.println("...MATT...");
  printer.inverseOff();
  printer.setSize('S');
  printer.println("Medical Adhesive Tape Test");
  printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: AUTOMATIC");
  printer.feed(1);
  printer.boldOn();
  printer.println("Tension Test");
  printer.boldOff();
  printer.feed(3);
 // printer.setSize('S');
 // printer.print("Average Force: ");
 // printer.print(avr);
 // printer.println("  N");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  Newton");
printer.feed(1);
  printer.print("Number of samples: ");
      printer.println(counter);
  printer.feed(1);
  printer.print("Speed ratio: ");
      printer.println("5 mm/s");

  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
     tft.begin(0x9341);
   tft.setRotation(3);
  loop();
}
} /////////////////////////////////////
  }
 ////////////////////////////////////////////////////////////////////////////////ROLLER PLATE
void rollerplate (void){
  tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Roller Plate Test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait... ");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("The head is going to be set in the       proper position");  
  while (digitalRead(sendown) == LOW) 
  {
  digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
delayMicroseconds(200);
digitalWrite(down, LOW);    
delayMicroseconds(200);
}
      for (int m=500; m>0; m--){
     digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
delayMicroseconds(200);
digitalWrite(up, LOW);    
delayMicroseconds(200);
  
  }
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Tension test.");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 105);
        tft.println("Please attache             Roller Plate. ");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);
        tft.println("Press START to start.");  
                       tft.setCursor(10, 230);
        tft.println("Press STOP to cancel.");
while (true){
if (digitalRead (startkey) == LOW){
break;
  }
  if (digitalRead (stopkey) == LOW){
terminate();
  }
}
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Test is in progress...");
tft.setTextColor(MAGENTA); 
tft.setTextSize(3);
       tft.setCursor(10, 100);
        tft.println("Please wait to finish the test.");
        tft.setTextColor(WHITE); tft.setTextSize(2);
               tft.setCursor(10, 200);

        tft.println("Press STOP to cancel.");
   scale.tare();   
         
 while (digitalRead(senmid) == LOW) 
  {
    while (digitalRead(senmid) == LOW) {
  kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;
for (int i=0; i<100 ; i++){
  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
  delay(1);                       
  digitalWrite(up, LOW);    
  delay(1); 
  digitalWrite (stopkey, HIGH);
  int key =0;
  key = digitalRead (stopkey);
   if (key == LOW) {

  terminate(); }
  }}

  }
      for (int m=500; m>0; m--){
     digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
  delay(1);                       
  digitalWrite(down, LOW);    
  delay(1);  
  
  }

  
   tft.setRotation(3);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(5, 50);
tft.println("Test Is Finshed.");
tft.setCursor(30, 104);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Avarege Force:");
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(300,100);
tft.println(avr);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 100);
tft.println(" Newton");
tft.setCursor(30, 134);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Maximum Force:");
tft.setCursor(300, 130);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(maxi);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 130);
tft.println(" Newton");
tft.setCursor(30, 164);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Number of samples:");
tft.setCursor(300, 160);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(counter);         
tft.setCursor(30, 194);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Speed rate:");
tft.setCursor(300, 190);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println("5 mm/s");
tft.setTextColor(CYAN);  tft.setTextSize(2);
tft.setCursor(5, 260);
tft.println("To print results press PRINT."); 
tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP.");     
        while (1){
if (digitalRead (stopkey) == LOW){
  tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(4);
tft.setCursor(5, 50);
tft.println("WARRNING!!!");
tft.setCursor(30, 104);
tft.setTextColor(WHITE);  tft.setTextSize(3);
tft.println("Remove plate's cable      from the head.");
tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP."); 
while(true){
if (digitalRead (stopkey) == LOW){
     loop();}}
}
if (digitalRead (printkey) == LOW){
             tft.reset();

 printer.begin();
  printer.inverseOn();
  printer.justify('C');
  printer.setSize('L');
  printer.println("...MATT...");
  printer.inverseOff();
  printer.setSize('S');
  printer.println("Medical Adhesive Tape Test");
  printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: AUTOMATIC");
  printer.feed(1);
  printer.boldOn();
  printer.println("Adhesive Test: Roller Plate");
  printer.boldOff();
  printer.feed(2);
  printer.setSize('S');
  printer.print("Average Force: ");
  printer.print(avr);
  printer.println("  Newton");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  Newton");
printer.feed(1);
  printer.print("Number of samples: ");
      printer.println(counter);
  printer.feed(1);
  printer.print("Speed ratio: ");
      printer.println("5 mm/s");

  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
     tft.begin(0x9341);
   tft.setRotation(3);

     tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(4);
tft.setCursor(5, 50);
tft.println("WARRNING!!!");
tft.setCursor(30, 104);
tft.setTextColor(WHITE);  tft.setTextSize(3);
tft.println("Remove plate's cable      from the head.");

tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 290);
tft.println("To restart press STOP."); 
while(true){
if (digitalRead (stopkey) == LOW){
  loop();}}
}
}    
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////MANUAL MODE
 void manualmode (void)
 {

 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
       tft.setCursor(20, 50);
        tft.println("Manual Mode is selected");
tft.setTextColor(WHITE);  tft.setTextSize(2);
       tft.setCursor(10, 150);
        tft.println("Press START to continiu.");
               tft.setCursor(10, 200);
        tft.println("Press STOP to cancel.");
         while (1){
    if (digitalRead (startkey) == LOW){
    goto manual;
  }
    if (digitalRead (stopkey) == LOW){
  terminate();
  }
  }
    manual:  
  /////////////////////////////////////////////////////////////////////////////////////////////////////////joystick
  kilo=0;
  maxi=0;
  counter=0;
  avr=0;
maxi=0;
sum=0;
int value =0;
 tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(2);
       tft.setCursor(5, 50);
        tft.println("Use Joystick to move head up and down.");  
               tft.setCursor(5, 100);
        tft.println(""); 
                       tft.setCursor(5, 150);
        tft.println("To finish test press STOP.");   
    tft.setTextColor(WHITE);  tft.setTextSize(4);

scale.tare();  
while(true)
 {
 delay(500);
  value = analogRead(joystic);
    value = value/100; 
    if (digitalRead (stopkey) == LOW){
     break;
    }/*//////
      kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;
    *///////

   while (value>7){
for(int i=200; i>1; i--){
  digitalWrite(down, HIGH);
  digitalWrite(up, HIGH);   
delayMicroseconds(700);
digitalWrite(up, LOW);    
delayMicroseconds(700);
}
  kilo =  scale.get_units(); 
  kilo=kilo/10000;
  kilo=kilo*1.15;
counter ++;
if (kilo > 70) alarm();
sum = sum+kilo;
avr = sum/counter;
if (kilo>maxi) maxi=kilo;
  value = analogRead(joystic);
    value = value/100; 
  }

  while( value<3){

     digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);   
delayMicroseconds(200);
digitalWrite(down, LOW);    
delayMicroseconds(200);
value = analogRead(joystic);
    value = value/100;
  }
}
tft.setRotation(3);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(5, 50);
tft.println("Test Is Finshed.");
tft.setCursor(30, 104);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Avarege Force:");
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.setCursor(300,100);
tft.println(avr);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 100);
tft.println(" Newton");
tft.setCursor(30, 134);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Maximum Force:");
tft.setCursor(300, 130);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(maxi);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.setCursor(390, 130);
tft.println(" Newton");
tft.setCursor(30, 164);
tft.setTextColor(WHITE);  tft.setTextSize(2);
tft.println("Number of samples:");
tft.setCursor(300, 160);
tft.setTextColor(YELLOW);  tft.setTextSize(3);
tft.println(counter);         
     

tft.setTextColor(MAGENTA);  tft.setTextSize(2);
tft.setCursor(5, 260);
tft.println("To restart press STOP.");     
        while (1){
if (digitalRead (stopkey) == LOW){
    goto manual;
}
if (digitalRead (resetkey) == LOW){
    loop();
}
if (digitalRead (printkey) == LOW){
             tft.reset();

 printer.begin();
  printer.inverseOn();
  printer.justify('C');
  printer.setSize('L');
  printer.println("...MATT...");
  printer.inverseOff();
  printer.setSize('S');
  printer.println("Medical Adhesive Tape Test");
  printer.feed(1);
  printer.justify('L');
  printer.println("Test Type: MANUAL");
  printer.feed(1);
  printer.boldOn();
  printer.println("Tension Test");
   printer.boldOff();
  printer.feed(2);
  printer.setSize('S');
  printer.print("Average Force: ");
  printer.print(avr);
  printer.println("  Newton");
  printer.feed(1);
  printer.print("Maximum Force: ");
    printer.print(maxi);
  printer.println("  Newton");
printer.feed(1);
  printer.print("Number of samples: ");
  
  printer.feed(2);
  printer.justify('C');
  printer.setSize('M');
  printer.println("WWW.DNP-CO.IR");
    printer.feed(1);
  printer.println("Tel: 09125221037");
  printer.feed(2);
  printer.setSize('S');
    printer.justify('C'); 
  printer.println("...End of report...");
  printer.feed(3);
  printer.wake();    
  printer.setDefault();
     tft.begin(0x9341);
   tft.setRotation(3);
  goto manual;

}
}  

 } 

Credits

mahdihir

mahdihir

0 projects • 1 follower

Comments