Difference between revisions of "Team:UMaryland/Design"

Line 256: Line 256:
 
<p> We have had one successful amplification with our machine however we understand that repeatability is a vital component of all lab work and currently we are attempting to make our device repeatable. From our early days of testing we found that peltier units were not powerful enough to enable PCR tube to reach 95 degrees. <strike>Although conventional PCR machines use these units frequently they are often specialized and tailored made to perform PCR. With this tailoring comes a high price tag that does not suit the DIY market, and so we found a solution in the form of a hairdryer. </strike><b>On the other hand, t</b>he fan and heating element of a <b>cheap </b>hairdryer provide a control scheme that enables for <b>rapid</b> cycling of temperature<strike> rapidly and accurately and they are relatively inexpensive</strike>. We have found that developing a housing for the PCR tubes and enabling even heat distribution is challenging. We often have found that our temperature sensor and the pcr reaction tube are not at the same temperature and degree of difference is a delta of over 10 degrees celsius<b>It is therefore NOT accurate, as described in previous sentences</b>. We are currently working of milling a block of aluminum with better and more consistent heat transfer properties, and modeling the heat transfer within the can. Our ambition is that this will enable better control of temperature within the device.         
 
<p> We have had one successful amplification with our machine however we understand that repeatability is a vital component of all lab work and currently we are attempting to make our device repeatable. From our early days of testing we found that peltier units were not powerful enough to enable PCR tube to reach 95 degrees. <strike>Although conventional PCR machines use these units frequently they are often specialized and tailored made to perform PCR. With this tailoring comes a high price tag that does not suit the DIY market, and so we found a solution in the form of a hairdryer. </strike><b>On the other hand, t</b>he fan and heating element of a <b>cheap </b>hairdryer provide a control scheme that enables for <b>rapid</b> cycling of temperature<strike> rapidly and accurately and they are relatively inexpensive</strike>. We have found that developing a housing for the PCR tubes and enabling even heat distribution is challenging. We often have found that our temperature sensor and the pcr reaction tube are not at the same temperature and degree of difference is a delta of over 10 degrees celsius<b>It is therefore NOT accurate, as described in previous sentences</b>. We are currently working of milling a block of aluminum with better and more consistent heat transfer properties, and modeling the heat transfer within the can. Our ambition is that this will enable better control of temperature within the device.         
 
<br></br>
 
<br></br>
<pre>
 
<font color="#000000">#include</font> <font color="#434f54">&lt;</font><font color="#000000">PID_v1</font><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">&gt;</font>
 
<font color="#000000">#include</font><font color="#434f54">&lt;</font><font color="#000000">math</font><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">&gt;</font>
 
<font color="#000000">#include</font> <font color="#434f54">&lt;</font><b><font color="#d35400">LiquidCrystal</font></b><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">&gt;</font>
 
 
<font color="#7e7e7e">/*The PID functions by adjusting a certain output in order to &nbsp;</font><font color="#7e7e7e"> * minimize the error between two values, which are the setpoint </font><font color="#7e7e7e"> * and the input.</font><font color="#7e7e7e"> * The PID function itself creates a PID controller and takes </font><font color="#7e7e7e"> * five parameters:</font><font color="#7e7e7e"> * Input: The value that needs to be controlled</font><font color="#7e7e7e"> * Output: The value that the PID will adjust</font><font color="#7e7e7e"> * Setpoint: The value that the input will be maintained at</font><font color="#7e7e7e"> * Kp,Ki,KD: Parameters that will affect how the output is adjusted</font><font color="#7e7e7e"> * Direct: Defines which direction the output will proceed given an error</font><font color="#7e7e7e"> */</font>
 
 
<font color="#434f54">// Define PID varaibles</font>
 
<font color="#00979c">double</font> <font color="#000000">Setpoint</font><font color="#434f54">,</font> <font color="#000000">Input</font><font color="#434f54">,</font> <font color="#000000">Output</font><font color="#000000">;</font>
 
<b><font color="#d35400">PID</font></b> <font color="#000000">myPID</font><font color="#000000">(</font><font color="#434f54">&</font><font color="#000000">Input</font><font color="#434f54">,</font> <font color="#434f54">&</font><font color="#000000">Output</font><font color="#434f54">,</font> <font color="#434f54">&</font><font color="#000000">Setpoint</font><font color="#434f54">,</font> <font color="#000000">1550</font><font color="#434f54">,</font> <font color="#000000">800</font><font color="#434f54">,</font> <font color="#000000">780</font><font color="#434f54">,</font> <font color="#d35400">DIRECT</font><font color="#000000">)</font><font color="#000000">;</font>
 
<font color="#434f54">//LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );</font>
 
  
 
 
<font color="#434f54">//PCR Variables</font>
 
<font color="#00979c">int</font> <font color="#000000">stepnow</font> <font color="#434f54">=</font> <font color="#000000">1</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">cycle</font> <font color="#434f54">=</font> <font color="#000000">2</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">laststep</font> <font color="#434f54">=</font> <font color="#000000">0</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">count</font> <font color="#434f54">=</font> <font color="#000000">1</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">startup</font> <font color="#434f54">=</font> <font color="#000000">2</font><font color="#000000">;</font>
 
 
<font color="#434f54">// Cycles</font>
 
<font color="#00979c">int</font> <font color="#000000">cycles</font> <font color="#434f54">=</font> <font color="#000000">35</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">cyclenum</font> <font color="#434f54">=</font> <font color="#000000">(</font><font color="#000000">cycles</font><font color="#434f54">-</font><font color="#000000">1</font><font color="#000000">)</font><font color="#434f54">*</font><font color="#000000">3</font> <font color="#434f54">+</font><font color="#000000">1</font><font color="#000000">;</font>
 
 
<font color="#434f54">//Startup cycle</font>
 
<font color="#00979c">int</font> <font color="#000000">meltT1</font> <font color="#434f54">=</font> <font color="#000000">96</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">pcrT1</font> <font color="#434f54">=</font> <font color="#000000">59</font><font color="#000000">;</font>
 
 
<font color="#434f54">//All cycles</font>
 
<font color="#00979c">int</font> <font color="#000000">meltT</font> <font color="#434f54">=</font> <font color="#000000">96</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">pcrT</font> <font color="#434f54">=</font> <font color="#000000">59</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">extensionT</font> <font color="#434f54">=</font> <font color="#000000">73</font><font color="#000000">;</font>
 
 
<font color="#434f54">//End cycle</font>
 
<font color="#00979c">int</font> <font color="#000000">endextT</font> <font color="#434f54">=</font> <font color="#000000">73</font><font color="#000000">;</font>
 
 
<font color="#00979c">int</font> <font color="#000000">endT</font> <font color="#434f54">=</font> <font color="#000000">4</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">deathT</font> <font color="#434f54">=</font> <font color="#000000">97</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">val0</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">val1</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">val</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">tempPin0</font> <font color="#434f54">=</font> <font color="#000000">2</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">tempPin1</font> <font color="#434f54">=</font> <font color="#000000">3</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">signalr1</font> <font color="#434f54">=</font> <font color="#000000">3</font><font color="#000000">;</font>
 
<font color="#00979c">int</font> <font color="#000000">signalr2</font> <font color="#434f54">=</font> <font color="#000000">5</font><font color="#000000">;</font>
 
<font color="#00979c">String</font> <font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"starting "</font><font color="#000000">;</font>
 
 
<font color="#00979c">boolean</font> <font color="#000000">cooling</font> <font color="#434f54">=</font> <font color="#000000">false</font><font color="#000000">;</font>
 
 
<font color="#434f54">//Startup cycle</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">Melt1</font> <font color="#434f54">=</font> <font color="#000000">180</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">t1Melt</font> <font color="#434f54">=</font> <font color="#000000">Melt1</font><font color="#434f54">*</font><font color="#000000">1000</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">PCR1</font> <font color="#434f54">=</font> <font color="#000000">20</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">t1PCR</font> <font color="#434f54">=</font> <font color="#000000">PCR1</font><font color="#434f54">*</font><font color="#000000">1000</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">extension1</font> <font color="#434f54">=</font> <font color="#000000">20</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">textension1</font> <font color="#434f54">=</font> <font color="#000000">extension1</font><font color="#434f54">*</font><font color="#000000">1000</font><font color="#000000">;</font>
 
 
<font color="#434f54">// All cycles</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">Melt</font> <font color="#434f54">=</font> <font color="#000000">30</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">tMelt</font> <font color="#434f54">=</font> <font color="#000000">Melt</font><font color="#434f54">*</font><font color="#000000">1000</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">PCR</font> <font color="#434f54">=</font> <font color="#000000">30</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">tPCR</font> <font color="#434f54">=</font> <font color="#000000">PCR</font><font color="#434f54">*</font><font color="#000000">1000</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">extension</font> <font color="#434f54">=</font> <font color="#000000">20</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">textension</font> <font color="#434f54">=</font> <font color="#000000">extension</font><font color="#434f54">*</font><font color="#000000">1000</font><font color="#000000">;</font>
 
 
<font color="#434f54">//End cycle</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">extend</font> <font color="#434f54">=</font> <font color="#000000">30</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">textend</font> <font color="#434f54">=</font> <font color="#000000">extend</font><font color="#434f54">*</font><font color="#000000">1000</font><font color="#000000">;</font>
 
 
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">cycleStart</font><font color="#000000">;</font>
 
 
 
<font color="#00979c">int</font> <font color="#000000">WindowSize</font> <font color="#434f54">=</font> <font color="#000000">500</font><font color="#000000">;</font>
 
<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">windowStartTime</font><font color="#000000">;</font>
 
 
 
<font color="#434f54">// Sets up the staring environment and will only run once</font>
 
<font color="#00979c">void</font> <font color="#5e6d03">setup</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">begin</font><font color="#000000">(</font><font color="#000000">9600</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;<font color="#434f54">//lcd.begin(16, 2);</font>
 
&nbsp;<font color="#000000">windowStartTime</font> <font color="#434f54">=</font> <font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;<font color="#000000">myPID</font><font color="#434f54">.</font><font color="#d35400">SetOutputLimits</font><font color="#000000">(</font><font color="#000000">0</font><font color="#434f54">,</font> <font color="#000000">WindowSize</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;<font color="#000000">myPID</font><font color="#434f54">.</font><font color="#d35400">SetMode</font><font color="#000000">(</font><font color="#d35400">AUTOMATIC</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#000000">signalr1</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#000000">signalr2</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;<font color="#000000">Setpoint</font> <font color="#434f54">=</font> <font color="#000000">meltT1</font><font color="#000000">;</font>
 
 
 
<font color="#000000">}</font>
 
 
<font color="#00979c">void</font> <font color="#5e6d03">loop</font><font color="#000000">(</font><font color="#000000">)</font>
 
<font color="#000000">{</font>
 
&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">stepnow</font> <font color="#434f54">&lt;</font> <font color="#000000">cyclenum</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;<font color="#7e7e7e">/**The following code is only implemented once as the first cycle of the PCR</font><font color="#7e7e7e"> &nbsp;&nbsp;&nbsp;&nbsp;* This allows for the user to set conditions which may be different from the subsequent </font><font color="#7e7e7e"> &nbsp;&nbsp;&nbsp;&nbsp;* cycles. The code, however, works in much the same way as the other cycles</font><font color="#7e7e7e"> &nbsp;&nbsp;&nbsp;&nbsp;* at the most basic level. It divides each cycle into subcycles: activation, pcr and extension</font><font color="#7e7e7e"> &nbsp;&nbsp;&nbsp;&nbsp;* and enters each step based on stepnow(which denotes how many subcyles the program has entered) divisiblity by 3. </font><font color="#7e7e7e"> &nbsp;&nbsp;&nbsp;&nbsp;* The remainder for activation will always be 1, </font><font color="#7e7e7e"> &nbsp;&nbsp;&nbsp;&nbsp;* the remainder for pcr will be 2 and the remainder for extension will be 3</font><font color="#7e7e7e"> &nbsp;&nbsp;&nbsp;&nbsp;*/</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">//Begins activation of the PCR by checking that this is the first cycle and that the current subcycle is activation </font>
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">stepnow</font> <font color="#434f54">%</font> <font color="#000000">3</font><font color="#000000">)</font> <font color="#434f54">==</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">cycle</font> <font color="#434f54">==</font> <font color="#000000">2</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">// sets the setpoint that the pcr will heat up to as meltT1</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">Setpoint</font> <font color="#434f54">=</font> <font color="#000000">meltT1</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">// prints out the current cycle number and the step it is currenly on</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">pcr</font> <font color="#434f54">+</font> <font color="#000000">count</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">// If the setpoint has reached the desired temperature, it will enter this loop</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">Input</font> <font color="#434f54">-</font> <font color="#000000">meltT1</font> <font color="#434f54">+</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">// Starts the timer and maintains this temperature for the desired amount of time</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cycleStart</font> <font color="#434f54">=</font> <font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"maintaining cycle activation: cycle "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">laststep</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">//If the pcr has maintained the setpoint for the desired amount of time, it will enter this loop and begin cooling</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">(</font><font color="#000000">t1Melt</font> <font color="#434f54">+</font> <font color="#000000">cycleStart</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">==</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">stepnow</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"cooling to pcr "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cooling</font> <font color="#434f54">=</font> <font color="#000000">true</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#434f54">// Checks that the current step is the subcycle pcr</font>
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">stepnow</font> <font color="#434f54">%</font> <font color="#000000">3</font><font color="#000000">)</font> <font color="#434f54">==</font> <font color="#000000">2</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">cycle</font> <font color="#434f54">==</font> <font color="#000000">2</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">// sets the temperature as pcrT1</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">Setpoint</font> <font color="#434f54">=</font> <font color="#000000">pcrT1</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">pcr</font> <font color="#434f54">+</font> <font color="#000000">count</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">//checks that the machine has reached the setpoint</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">Input</font> <font color="#434f54">-</font> <font color="#000000">pcrT1</font> <font color="#434f54">-</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&lt;</font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cooling</font> <font color="#434f54">=</font> <font color="#000000">false</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cycleStart</font> <font color="#434f54">=</font> <font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"maintaining cycle pcr: cycle "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">laststep</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">//checks if the machine has maintained the temperature for the desired amount of time, and begins the next step</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">(</font><font color="#000000">t1PCR</font> <font color="#434f54">+</font> <font color="#000000">cycleStart</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">==</font> <font color="#000000">stepnow</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">cycle</font> <font color="#434f54">==</font> <font color="#000000">2</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">stepnow</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"heating to extension "</font><font color="#000000">;</font>
 
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#434f54">// Checks that the current step is the subcycle extension</font>
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">cycle</font> <font color="#434f54">==</font> <font color="#000000">2</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">stepnow</font> <font color="#434f54">%</font> <font color="#000000">3</font><font color="#000000">)</font> <font color="#434f54">==</font> <font color="#000000">0</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">// sets the temperature as extensionT</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">Setpoint</font> <font color="#434f54">=</font> <font color="#000000">extensionT</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">pcr</font> <font color="#434f54">+</font> <font color="#000000">count</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">//checks that the machine has reached the setpoint</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">Input</font> <font color="#434f54">-</font> <font color="#000000">extensionT</font> <font color="#434f54">+</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"maintaining cycle extension: cycle "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cycleStart</font> <font color="#434f54">=</font> <font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">laststep</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#434f54">//checks if the machine has maintained the temperature for the desired amount of time, and begins the next step</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">(</font><font color="#000000">textension1</font> <font color="#434f54">+</font> <font color="#000000">cycleStart</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">==</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"heating to melt "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">stepnow</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cycle</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">count</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
 
<font color="#7e7e7e">/**</font><font color="#7e7e7e"> * Begins the intermediate steps which work in an identical manner to the startup cycle </font><font color="#7e7e7e"> * and may differ only in the alloted temperatures and times for each subcycle</font><font color="#7e7e7e"> */</font>
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">stepnow</font> <font color="#434f54">%</font> <font color="#000000">3</font><font color="#000000">)</font> <font color="#434f54">==</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">cycle</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">2</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">Setpoint</font> <font color="#434f54">=</font> <font color="#000000">meltT</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">pcr</font> <font color="#434f54">+</font> <font color="#000000">count</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">Input</font> <font color="#434f54">-</font> <font color="#000000">meltT</font> <font color="#434f54">+</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"maintaining melt: cycle "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cycleStart</font> <font color="#434f54">=</font> <font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">laststep</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">(</font><font color="#000000">tMelt</font> <font color="#434f54">+</font> <font color="#000000">cycleStart</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">==</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">stepnow</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cooling</font> <font color="#434f54">=</font> <font color="#000000">true</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"cooling to pcr "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">stepnow</font> <font color="#434f54">%</font> <font color="#000000">3</font><font color="#000000">)</font> <font color="#434f54">==</font> <font color="#000000">2</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">cycle</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">2</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">Setpoint</font> <font color="#434f54">=</font> <font color="#000000">pcrT</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">pcr</font> <font color="#434f54">+</font> <font color="#000000">count</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">Input</font> <font color="#434f54">-</font> <font color="#000000">pcrT</font> <font color="#434f54">-</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&lt;</font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cooling</font> <font color="#434f54">=</font> <font color="#000000">false</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"maintaining pcr: cycle "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cycleStart</font> <font color="#434f54">=</font> <font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">laststep</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">(</font><font color="#000000">tPCR</font> <font color="#434f54">+</font> <font color="#000000">cycleStart</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">==</font> <font color="#000000">stepnow</font><font color="#000000">)</font> <font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">stepnow</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"heating to extension "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">stepnow</font> <font color="#434f54">%</font> <font color="#000000">3</font><font color="#000000">)</font> <font color="#434f54">==</font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">cycle</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">2</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">Setpoint</font> <font color="#434f54">=</font> <font color="#000000">extensionT</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">pcr</font> <font color="#434f54">+</font> <font color="#000000">count</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">Input</font> <font color="#434f54">-</font> <font color="#000000">extensionT</font> <font color="#434f54">+</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cycleStart</font> <font color="#434f54">=</font> <font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"maintaining extension: cycle "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">laststep</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">(</font><font color="#000000">textension</font> <font color="#434f54">+</font> <font color="#000000">cycleStart</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">==</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">stepnow</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">count</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"heating to melt "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;<font color="#7e7e7e">/*</font><font color="#7e7e7e"> &nbsp;&nbsp;* Begins the last step, which again works in a similar fashion to the other steps, but may differ in the </font><font color="#7e7e7e"> &nbsp;&nbsp;* final extension temperature</font><font color="#7e7e7e"> &nbsp;&nbsp;*/</font>
 
&nbsp;<font color="#000000">}</font> <font color="#5e6d03">else</font> <font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">stepnow</font> <font color="#434f54">&gt;</font><font color="#434f54">=</font> <font color="#000000">cyclenum</font> <font color="#434f54">&&</font> <font color="#000000">stepnow</font> <font color="#434f54">&lt;</font><font color="#434f54">=</font> <font color="#000000">cyclenum</font> <font color="#434f54">+</font> <font color="#000000">2</font> <font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">stepnow</font> <font color="#434f54">%</font> <font color="#000000">3</font><font color="#000000">)</font> <font color="#434f54">==</font> <font color="#000000">1</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">Setpoint</font> <font color="#434f54">=</font> <font color="#000000">meltT</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">pcr</font> <font color="#434f54">+</font> <font color="#000000">count</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">Input</font> <font color="#434f54">-</font> <font color="#000000">meltT</font> <font color="#434f54">+</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"maintaining melt: cycle "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cycleStart</font> <font color="#434f54">=</font> <font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">laststep</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">(</font><font color="#000000">tMelt</font> <font color="#434f54">+</font> <font color="#000000">cycleStart</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">==</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">stepnow</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cooling</font> <font color="#434f54">=</font> <font color="#000000">true</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"cooling to pcr "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">stepnow</font> <font color="#434f54">%</font> <font color="#000000">3</font><font color="#000000">)</font> <font color="#434f54">==</font> <font color="#000000">2</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">Setpoint</font> <font color="#434f54">=</font> <font color="#000000">pcrT</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">pcr</font> <font color="#434f54">+</font> <font color="#000000">count</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">Input</font> <font color="#434f54">-</font> <font color="#000000">pcrT</font> <font color="#434f54">-</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&lt;</font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cooling</font> <font color="#434f54">=</font> <font color="#000000">false</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"maintaining pcr: cycle "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cycleStart</font> <font color="#434f54">=</font> <font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">laststep</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">(</font><font color="#000000">tPCR</font> <font color="#434f54">+</font> <font color="#000000">cycleStart</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">==</font> <font color="#000000">stepnow</font><font color="#000000">)</font> <font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">stepnow</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"heating to extension "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">stepnow</font> <font color="#434f54">%</font> <font color="#000000">3</font><font color="#000000">)</font> <font color="#434f54">==</font> <font color="#000000">0</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">Setpoint</font> <font color="#434f54">=</font> <font color="#000000">extensionT</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">pcr</font> <font color="#434f54">+</font> <font color="#000000">count</font><font color="#000000">)</font><font color="#000000">;</font>
 
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#000000">Input</font> <font color="#434f54">-</font> <font color="#000000">extensionT</font> <font color="#434f54">+</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">!</font><font color="#434f54">=</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">cycleStart</font> <font color="#434f54">=</font> <font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"maintaining extension: cycle "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">laststep</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">(</font><font color="#000000">textend</font> <font color="#434f54">+</font> <font color="#000000">cycleStart</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#434f54">&&</font> <font color="#000000">(</font><font color="#000000">laststep</font> <font color="#434f54">==</font> <font color="#000000">stepnow</font><font color="#000000">)</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">stepnow</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">count</font><font color="#434f54">++</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"cooling to end "</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;<font color="#7e7e7e">/**</font><font color="#7e7e7e"> &nbsp;&nbsp;* Once the last step has been completed, determined by stepnow being greater than cyclenum+2,</font><font color="#7e7e7e"> &nbsp;&nbsp;* the code will tell the pcr to hold at 4 C. It will continue looping at this step indefinitely</font><font color="#7e7e7e"> &nbsp;&nbsp;* because the conditions will no longer satisfy any of the other if statement</font><font color="#7e7e7e"> &nbsp;&nbsp;*/</font>
 
&nbsp;<font color="#000000">}</font> <font color="#5e6d03">else</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;<font color="#00979c">int</font> <font color="#000000">strt</font> <font color="#434f54">=</font> <font color="#000000">1</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;<font color="#00979c">boolean</font> <font color="#000000">cooldown</font> <font color="#434f54">=</font> <font color="#000000">true</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">strt</font> <font color="#434f54">==</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">Setpoint</font> <font color="#434f54">=</font> <font color="#000000">endT</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">pcr</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#434f54">// begins cooldown to 4 </font>
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">cooldown</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr1</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr2</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
 
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;&nbsp;&nbsp;<font color="#434f54">//Once the pcr has reached 37 C, the pcr will print out that the pcr has shutt off</font>
 
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">Input</font> <font color="#434f54">-</font> <font color="#000000">38</font> <font color="#434f54">+</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&lt;</font> <font color="#000000">0</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr1</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr2</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pcr</font> <font color="#434f54">=</font> <font color="#00979c">"turn off"</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
 
&nbsp;<font color="#000000">}</font>
 
<font color="#434f54">// creates the window </font>
 
&nbsp;<font color="#00979c">unsigned</font> <font color="#00979c">long</font> <font color="#000000">now</font> <font color="#434f54">=</font> <font color="#d35400">millis</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">now</font> <font color="#434f54">-</font> <font color="#000000">windowStartTime</font> <font color="#434f54">&gt;</font> <font color="#000000">WindowSize</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">windowStartTime</font> <font color="#434f54">+=</font> <font color="#000000">WindowSize</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">Input</font> <font color="#434f54">=</font> <font color="#000000">val</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;<font color="#434f54">// this function is called once every loop, and contains the pid algorithm </font>
 
&nbsp;&nbsp;&nbsp;<font color="#000000">myPID</font><font color="#434f54">.</font><font color="#d35400">Compute</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;
 
 
&nbsp;<font color="#000000">}</font>
 
<font color="#434f54">// if cooling is true, it will begin cooling until cool is set to false</font>
 
&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">cooling</font><font color="#000000">)</font><font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr1</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr2</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#00979c">"COOLING"</font><font color="#000000">)</font><font color="#000000">;</font>
 
<font color="#434f54">// if the pcr machine's temperature reaches 97, cooling will automatically be initiated and a death message will be displayed</font>
 
&nbsp;<font color="#000000">}</font><font color="#5e6d03">else</font> <font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">Input</font> <font color="#434f54">-</font> <font color="#000000">deathT</font> <font color="#434f54">+</font><font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">)</font><font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr1</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr2</font><font color="#434f54">,</font> <font color="#00979c">LOW</font> <font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#00979c">"DEATH"</font><font color="#000000">)</font><font color="#000000">;</font>
 
 
<font color="#7e7e7e">/* these two statements work on the maintaining the temperature, by controlling heating and cooling when there is overshoot or undershoot </font><font color="#7e7e7e"> &nbsp;&nbsp;in the temperature*/</font>
 
&nbsp;<font color="#000000">}</font> <font color="#5e6d03">else</font> <font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">Output</font> <font color="#434f54">&gt;</font> <font color="#000000">now</font> <font color="#434f54">-</font> <font color="#000000">windowStartTime</font> <font color="#434f54">-</font> <font color="#000000">1</font><font color="#000000">)</font> <font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr1</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr2</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;<font color="#000000">}</font>
 
&nbsp;<font color="#5e6d03">else</font>
 
&nbsp;<font color="#000000">{</font>
 
&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr1</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">signalr2</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
 
 
&nbsp;&nbsp;&nbsp;
 
&nbsp;<font color="#000000">}</font>
 
&nbsp;<font color="#434f54">//int reading = analogRead(tempPin);</font>
 
&nbsp;<font color="#000000">val0</font> <font color="#434f54">=</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#d35400">analogRead</font><font color="#000000">(</font><font color="#000000">tempPin0</font><font color="#000000">)</font> <font color="#434f54">/</font> <font color="#000000">1024.0</font><font color="#000000">)</font> <font color="#434f54">*</font> <font color="#000000">5000</font><font color="#000000">)</font> <font color="#434f54">/</font> <font color="#000000">10</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;<font color="#000000">val1</font> <font color="#434f54">=</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">(</font><font color="#d35400">analogRead</font><font color="#000000">(</font><font color="#000000">tempPin1</font><font color="#000000">)</font> <font color="#434f54">/</font> <font color="#000000">1024.0</font><font color="#000000">)</font> <font color="#434f54">*</font> <font color="#000000">5000</font><font color="#000000">)</font> <font color="#434f54">/</font> <font color="#000000">10</font><font color="#000000">)</font><font color="#000000">;</font>
 
 
&nbsp;<font color="#434f54">//val = (val0 + val1)/2;</font>
 
&nbsp;<font color="#000000">val</font> <font color="#434f54">=</font> <font color="#000000">val1</font><font color="#000000">;</font>
 
<font color="#434f54">// determines the value of the current temperature and prints it out</font>
 
&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">val</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;
 
<font color="#434f54">// loops back to the top of the code, this will occur indefinitely</font>
 
 
<font color="#000000">}</font>
 
 
</pre>
 
  
 
<div>
 
<div>

Revision as of 21:45, 18 September 2015