PCR Machine Project

PCR Project Pictures

Teacher Notes: All HTML and CSS for this site was hand typed in a text editor. No development environment was used so that the students learn HTML.


PCR Code

pcrProgMk1.ino

	/*
	NOTE TO READER OF pcrProgMk1.ino: The code in the main loop may not be
	exactly what is in the actual machine code. It may be different depending
	on what specific process of PCR the machine is doing. As for the code
	that is commented out at the bottom, that is code that was previously in
	the program, but that has since been taken out for improvement of the program.
	*/
	
	#include "deviceDriver.h"
	#include "pcrAPI.h"
	#include < LiquidCrystal.h >
	#include < SPI.h >
	#include "Adafruit_MAX31855.h"

	deviceDriver usedByApi;
	pcrAPI pcrControler;

	bool startTemp = false;
	String tempConversion;

	void setup() {
	}

	void loop() {
	  for(int cycles = 0; cycles < 30; cycles++)
	  {
	    pcrControler.heatFunction(201.00, 203.00, 0, 2, 1, 23000, 2, cycles);
	    pcrControler.coolFunction(122.00, 140.00, 0, 2, 1, 20000, 2, cycles);
	    pcrControler.heatFunction(160.00, 163.00, 0, 2, 1, 25000, 2, cycles);
	  }
   
	  for(int x = 0; x < 4; x++)
	  {
	    funcControl.printStrings("                    ", x); //20 spaces, the width of the lcd screen
	  }
	
	  while(true)
	  {  
	    usedByApi.printStrings("    Process Done    ", 1);
	    usedByApi.printStrings("  Get Your Samples  ", 2);
	    delay(1000);
	    usedByApi.printStrings("  * Process Done *  ", 1);
	    delay(1000);
	  }  
	}

	
	/*
	pcrControler.heatFunction(90.00, 100.00, 0, 2, 1, 30000, 2);
	delay(5000);

	usedByApi.turnOnFan();
  
	while(true);
	*/

	/*
	pcrControler.heatFunction(90.00, 100.00, 0, 2, 1, 30000, 2);
	delay(5000);
  
	pcrControler.coolFunction(75.00, 78.00, 0, 2, 1, 30000, 2);
	delay(5000);
  
	usedByApi.turnOnFan();
  
	while(true);
	*/

	/*
	pcrControler.heatFunction(201.00, 205.00, 0, 2, 1, 30000, 2);
	delay(5000);
  
	pcrControler.coolFunction(122.00, 149.00, 0, 2, 1, 30000, 2);
	delay(5000);
  
	usedByApi.turnOnFan();
  
	while(true);
	*/

	/*
	usedByApi.turnOnFan();
	delay(20000);
	usedByApi.turnOffFan();
  
	pcrControler.heatFunction(80.00, 85.00, 0, 2, 1, 30000, 2);
	delay(5000);
	*/

	/*
	usedByApi.turnOnFan();
    
	while(startTemp == false)
	{	
	delay(3000);
   
	tempConversion = String(usedByApi.readTemp());
	usedByApi.printStrings(tempConversion + "F  ", 0);
   
	if(usedByApi.readTemp() >= 70.00 & usedByApi.readTemp() <= 78.00)
	{
	usedByApi.turnOffFan();
	return;
	}
	}
	*/
	
	
	

deviceDriver.h

	#ifndef DEVICEDRIVER_H
	#define DEVICEDRIVER_H

	#include < Arduino.h >
	#include < LiquidCrystal.h >
	const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
	
	#include < SPI.h >
	#include "Adafruit_MAX31855.h"
	#define MAXDO   9 
	#define MAXCS   7
	#define MAXCLK  6

	class deviceDriver
	{
	  public:
	  deviceDriver();
	  void turnOnFan();  
	  void turnOffFan();
	  float readTemp();
	  void resistorsRun();
	  void resistorsStop();
	  void printStrings(String s, int lineNumber);
	  void printFloats(float number, int lineNumber);

	  private:
	  LiquidCrystal * lcd;
	  int fanPin;    
	  double f;    
	  int resistorPin;
	};

	#endif
	

deviceDriver.cpp

	#include "deviceDriver.h"

	Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);
	
	deviceDriver::deviceDriver()
	{
	  lcd = new LiquidCrystal(rs, en, d4, d5, d6, d7);
	  lcd->begin(20,4);
	  lcd->setCursor(0, 0);

	  fanPin = 10;
	  pinMode(fanPin,OUTPUT);
	  digitalWrite(fanPin,LOW);
	  	  
	  resistorPin = 8;
	  pinMode(resistorPin,OUTPUT);
	  digitalWrite(resistorPin, LOW);
	}

	void deviceDriver::turnOnFan()
	{
	  digitalWrite(fanPin, HIGH);
	}
 
	void deviceDriver::printStrings(String s, int lineNumber)
	{
	  lcd->setCursor(0, lineNumber);
	  lcd->print(s); 
	}

	void deviceDriver::printFloats(float number, int lineNumber)
	{
	  lcd->setCursor(0, lineNumber);
	  lcd->print(number);
	}
 
	void deviceDriver::turnOffFan()
	{
	  digitalWrite(fanPin, LOW);
	}

	float deviceDriver::readTemp()
	{
	  return thermocouple.readFarenheit();
	}

	void deviceDriver::resistorsRun()
	{
	  digitalWrite(resistorPin, HIGH);
	}

	void deviceDriver::resistorsStop()
	{
	  digitalWrite(resistorPin, LOW);
	}
	

pcrAPI.h

	#ifndef pcrAPI_H
	#define pcrAPI_H

	#include < Arduino.h >
	#include "deviceDriver.h"

	class pcrAPI
	{
	  public:
	  void heatFunction(float lowerTemp, float higherTemp, int rangeLine, int rngReachedLine, int tempLine, int tempDuration, int durationLine, int passedCycles);		
	  void coolFunction(float lowerTemp, float higherTemp, int rangeLine, int rngReachedLine, int tempLine, int tempDuration, int durationLine, int passedCycles);
  
	  private:
	  bool rangeReached = false;
	  bool rangeAchieved = false;
	  bool durationEnded = false;
  
	  float time1 = 0;
	  float time2 = 0;
	  float answer = 0;

	  float stringTemp = 00.00;
  
	  String numberConversion_1;
	  String numberConversion_2;
	  String numberConversion_3;
	  
	  String cyclesConversion;
  
	  void heatToRange(float lowerTemp, float higherTemp, int rangeLine, int rngReachedLine, int tempLine, int passedCycles);
	  void coolToRange(float lowerTemp, float higherTemp, int rangeLine, int rngReachedLine, int tempLine, int passedCycles);
	  void keepTempConstant(float lowerTemp, float higherTemp, int tempLine, int rangeLine, int tempDuration, int durationLine, int passedCycles);
  
	  deviceDriver funcControl;
	};

	#endif
	

pcrAPI.cpp

	#include "pcrAPI.h"

	deviceDriver funcControl;

	void pcrAPI::heatToRange(float lowerTemp, float higherTemp, int rangeLine, int rngReachedLine, int tempLine, int passedCycles)
	{
	  numberConversion_1 = String(lowerTemp);
	  numberConversion_2 = String(higherTemp);
	  funcControl.printStrings(numberConversion_1 + "F - " + numberConversion_2 + "F", rangeLine);

	  stringTemp = funcControl.readTemp();
	  numberConversion_3 = String(stringTemp);
	  funcControl.printStrings(numberConversion_3 + "   ", tempLine);
  
	  rangeReached = false;
	  funcControl.printStrings("rangeReached:FALSE ", rngReachedLine);
	    
	  cyclesConversion = String(passedCycles);
	  funcControl.printStrings("          Cs.Dn: " + cyclesConversion, tempLine);
		
	  while(rangeReached == false)
	  {
	    funcControl.printFloats(funcControl.readTemp(), tempLine);
   
	    if(funcControl.readTemp() < lowerTemp)
	    {  
	      if(funcControl.readTemp() >= lowerTemp - 1.00 & funcControl.readTemp() < lowerTemp)
	      {
	        delay(5500);
	      }
	      else
	      {
	        funcControl.resistorsRun();
	        delay(5000);
	        funcControl.resistorsStop();
	        delay(500); 
	      }
	    }
	    else if(funcControl.readTemp() >= lowerTemp & funcControl.readTemp() < higherTemp)
	    {
	      rangeReached = true;
	      funcControl.printStrings("rangeReached:TRUE ", rngReachedLine);
	      delay(2000);
	    }
	  }
   
	  for(int x = 0; x < 4; x++)
	  {
	    funcControl.printStrings("                    ", x); //20 spaces, the width of the lcd screen
	  }
	}

	void pcrAPI::coolToRange(float lowerTemp, float higherTemp, int rangeLine, int rngReachedLine, int tempLine, int passedCycles)
	{
	  numberConversion_1 = String(lowerTemp);
	  numberConversion_2 = String(higherTemp);
	  funcControl.printStrings(numberConversion_1 + "F - " + numberConversion_2 + "F", rangeLine);

	  funcControl.printFloats(funcControl.readTemp(), tempLine);
 
	  rangeReached = false;
	  funcControl.printStrings("rangeReached:FALSE ", rngReachedLine);
	  
	  cyclesConversion = String(passedCycles);
	  funcControl.printStrings("          Cs.Dn: " + cyclesConversion, tempLine);

	  funcControl.turnOnFan();
  
	  while(rangeReached == false)
	  {
	    funcControl.printFloats(funcControl.readTemp(), tempLine);
       
	    if(funcControl.readTemp() > higherTemp)
	    {
	      delay(3000);
	    }
	    else if (funcControl.readTemp() > lowerTemp & funcControl.readTemp() < higherTemp)
	    {
	      delay(3000); //allows temperature to be in the middle of the temperature range
	      rangeReached = true;
	      funcControl.turnOffFan();
	      funcControl.printStrings("rangeReached:TRUE ", rngReachedLine);
	      delay(2000);
	    }
	  }
  
	  for(int x = 0; x < 4; x++)
	  {
	    funcControl.printStrings("                    ", x); //20 spaces, the width of the lcd screen
	  }
	}
	
	void pcrAPI::keepTempConstant(float lowerTemp, float higherTemp, int tempLine, int rangeLine, int tempDuration, int durationLine, int passedCycles)
	{
	  numberConversion_1 = String(lowerTemp);
	  numberConversion_2 = String(higherTemp);
	  funcControl.printStrings(numberConversion_1 + "F - " + numberConversion_2 + "F", rangeLine);

	  funcControl.printFloats(funcControl.readTemp(), tempLine);
  
	  time1 = 0;
	  time2 = 0;
	  answer = 0;
 
	  durationEnded = false;
	  funcControl.printStrings("durationEnded:FALSE ", durationLine);
	  
	  cyclesConversion = String(passedCycles);
	  funcControl.printStrings("          Cs.Dn: " + cyclesConversion, tempLine);
  
	  time1 = millis();

	  while(durationEnded == false)
	  {
	    funcControl.printFloats(funcControl.readTemp(), tempLine);

	    delay(5000);
   
	    time2 = millis();
	    answer = time2 - time1;
	    funcControl.printFloats(answer / 1000, durationLine + 1);

	    if(answer >= tempDuration)
	    {
	      durationEnded = true;
	      funcControl.printStrings("durationEnded:TRUE ", durationLine);
	      delay(2000);
    
	      for(int x = 0; x < 4; x++)
	      {
	        funcControl.printStrings("                    ", x); //20 spaces, the width of the lcd screen
	      }
    
	      return;
	    }
	    else
	    {
	      funcControl.printFloats(funcControl.readTemp(), tempLine);

	      if(funcControl.readTemp() > higherTemp)
	      {
	        rangeAchieved = false;
	        funcControl.turnOnFan();
      
	        while(rangeAchieved == false)
	        {
	          if(funcControl.readTemp() > lowerTemp & funcControl.readTemp() < higherTemp)
	          {
	            rangeAchieved = true;
	            funcControl.turnOffFan();
	          }
	        }
	      }
	      else if(funcControl.readTemp() < lowerTemp)
	      {
	        rangeAchieved = false;

	        while(rangeAchieved == false)
	        {
	          funcControl.resistorsRun();
	          delay(5000);
       
	          if(funcControl.readTemp() > lowerTemp & funcControl.readTemp() < higherTemp)
	          {
	            rangeAchieved = true;
	            funcControl.resistorsStop();
	          }
	          else
	          {
	            funcControl.resistorsStop();
	            delay(5000);
	          }
	        }
	      }
	    }
	  }
  
	  for(int x = 0; x < 4; x++)
	  {
	    funcControl.printStrings("                    ", x); //20 spaces, the width of the lcd screen
	  }
	}

	void pcrAPI::heatFunction(float lowerTemp, float higherTemp, int rangeLine, int rngReachedLine, int tempLine, int tempDuration, int durationLine, int passedCycles)
	{
	  heatToRange(lowerTemp, higherTemp, rangeLine, rngReachedLine, tempLine, passedCycles);
	  keepTempConstant(lowerTemp, higherTemp, tempLine, rangeLine, tempDuration, durationLine, passedCycles);
	}

	void pcrAPI::coolFunction(float lowerTemp, float higherTemp, int rangeLine, int rngReachedLine, int tempLine, int tempDuration, int durationLine, int passedCycles)
	{
	  coolToRange(lowerTemp, higherTemp, rangeLine, rngReachedLine, tempLine, passedCycles);
	  keepTempConstant(lowerTemp, higherTemp, tempLine, rangeLine, tempDuration, durationLine, passedCycles);
	}