<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://shawnreeves.net//wiki/index.php?action=history&amp;feed=atom&amp;title=Photo-gate_timer_with_an_Arduino</id>
	<title>Photo-gate timer with an Arduino - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://shawnreeves.net//wiki/index.php?action=history&amp;feed=atom&amp;title=Photo-gate_timer_with_an_Arduino"/>
	<link rel="alternate" type="text/html" href="https://shawnreeves.net//wiki/index.php?title=Photo-gate_timer_with_an_Arduino&amp;action=history"/>
	<updated>2026-06-01T19:04:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://shawnreeves.net//wiki/index.php?title=Photo-gate_timer_with_an_Arduino&amp;diff=2930&amp;oldid=prev</id>
		<title>Shawn: /* Program listing */ syntax highlighting</title>
		<link rel="alternate" type="text/html" href="https://shawnreeves.net//wiki/index.php?title=Photo-gate_timer_with_an_Arduino&amp;diff=2930&amp;oldid=prev"/>
		<updated>2025-03-31T02:17:57Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Program listing: &lt;/span&gt; syntax highlighting&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:17, 30 March 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l3&quot;&gt;Line 3:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;See [[Photo-gate timer]] for a full discussion.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;See [[Photo-gate timer]] for a full discussion.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;syntaxhighlight lang=&quot;C++&quot; line copy&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;//By Shawn Reeves. 2014.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;//By Shawn Reeves. 2014.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  //Compile in Arduino IDE. Requires PinChangeInt library that isn&amp;#039;t part of standard install.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  //Compile in Arduino IDE. Requires PinChangeInt library that isn&amp;#039;t part of standard install.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l194&quot;&gt;Line 194:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 194:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    Wire.endTransmission();    // stop transmitting&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    Wire.endTransmission();    // stop transmitting&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  }&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  }&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Electronics]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Electronics]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Shawn</name></author>
	</entry>
	<entry>
		<id>https://shawnreeves.net//wiki/index.php?title=Photo-gate_timer_with_an_Arduino&amp;diff=2698&amp;oldid=prev</id>
		<title>Shawn at 20:31, 9 May 2014</title>
		<link rel="alternate" type="text/html" href="https://shawnreeves.net//wiki/index.php?title=Photo-gate_timer_with_an_Arduino&amp;diff=2698&amp;oldid=prev"/>
		<updated>2014-05-09T20:31:13Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:31, 9 May 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Program listing===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Program listing===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This program can be compiled for &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;a PICAXE 20M2&lt;/del&gt;, paired with a Newhaven 3V i2c LCD display. It will watch for low signals on five input pins.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This program can be compiled for &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;an Atmel 328P, running at 2MHz (!)&lt;/ins&gt;, paired with a Newhaven 3V i2c LCD display. It will watch for low signals on five input pins.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;See [[Photo-gate timer]] for a full discussion.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;See [[Photo-gate timer]] for a full discussion.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Shawn</name></author>
	</entry>
	<entry>
		<id>https://shawnreeves.net//wiki/index.php?title=Photo-gate_timer_with_an_Arduino&amp;diff=2685&amp;oldid=prev</id>
		<title>Shawn: Created page with &quot;===Program listing=== This program can be compiled for a PICAXE 20M2, paired with a Newhaven 3V i2c LCD display. It will watch for low signals on five input pins.  See [[Photo...&quot;</title>
		<link rel="alternate" type="text/html" href="https://shawnreeves.net//wiki/index.php?title=Photo-gate_timer_with_an_Arduino&amp;diff=2685&amp;oldid=prev"/>
		<updated>2014-05-09T02:31:11Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;===Program listing=== This program can be compiled for a PICAXE 20M2, paired with a Newhaven 3V i2c LCD display. It will watch for low signals on five input pins.  See [[Photo...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;===Program listing===&lt;br /&gt;
This program can be compiled for a PICAXE 20M2, paired with a Newhaven 3V i2c LCD display. It will watch for low signals on five input pins.&lt;br /&gt;
&lt;br /&gt;
See [[Photo-gate timer]] for a full discussion.&lt;br /&gt;
&lt;br /&gt;
//By Shawn Reeves. 2014.&lt;br /&gt;
 //Compile in Arduino IDE. Requires PinChangeInt library that isn&amp;#039;t part of standard install.&lt;br /&gt;
 /*On timing:&lt;br /&gt;
 micros() returns the number of microseconds since the Arduino board began running the current program.&lt;br /&gt;
 micros() returns an unsigned long integer, so it overflows to zero after 4,294,967,295 µs.&lt;br /&gt;
 millis() is similar except it counts milliseconds.&lt;br /&gt;
 NOTA BENE:Both millis() and micros() clear interrupts while they read the timer, so use them sparingly!&lt;br /&gt;
 */&lt;br /&gt;
 /*On interrupts:&lt;br /&gt;
 The Atmega 328 only has two fully independent hardware interrupts, but it has more grouped-pin interrupts.&lt;br /&gt;
 We use the PinChangeInt library to enable the PCINT on the Atmega328 ports.&lt;br /&gt;
 We&amp;#039;ve programmed using switch...case so that the gates can be tripped in any order,&lt;br /&gt;
  but their position in the display goes by how they are hardwired.&lt;br /&gt;
 What if two interrupts happen simultaneously?&lt;br /&gt;
  If two interrupts happen withing microseconds of each other, we might be processing and displaying one&lt;br /&gt;
  and mixing up the values.&lt;br /&gt;
  So, we should have an array of hit_time variables for each gate.&lt;br /&gt;
  This way this can be used as a race-track timer without fear of complications.&lt;br /&gt;
 */&lt;br /&gt;
 #include &amp;lt;PinChangeInt.h&amp;gt;&lt;br /&gt;
 //Assign meaningful names to the pins&lt;br /&gt;
 /*Since we are going to cause interrupt on a change on every pin of an involved port,&lt;br /&gt;
 let&amp;#039;s pick fewest number of ports. If there aren&amp;#039;t five free pins on any port, then one for the first gate&lt;br /&gt;
 and another for the rest of the gates.&lt;br /&gt;
 If using i2c, avoid Port C, since it is partly used for i2c with display.&lt;br /&gt;
 If using SPI, avoid Port B.&lt;br /&gt;
 If using UART Serial, avoid Port D.&lt;br /&gt;
 */&lt;br /&gt;
 #define gate0 8   //328 pin 14&lt;br /&gt;
 #define gate1 2   //328 pin 4&lt;br /&gt;
 #define gate2 3   //328 pin 5&lt;br /&gt;
 #define gate3 10  //328 pin 16&lt;br /&gt;
 #define gate4 9   //328 pin 15&lt;br /&gt;
 /*On LCD display&lt;br /&gt;
 We are using an i2c LCD display from Newhaven Display.&lt;br /&gt;
 The Wire library sends i2c commands and data.&lt;br /&gt;
 */&lt;br /&gt;
 #include &amp;lt;Wire.h&amp;gt;&lt;br /&gt;
 #define LCD_address 0x3E  //0x7C shifted right one bit&lt;br /&gt;
 #define command_send 0  //prefix commands to the i2c LCD&lt;br /&gt;
 #define data_send 0x40&lt;br /&gt;
 #define line2_address 0xC0&lt;br /&gt;
 //Declare variables to track interrupt pins:&lt;br /&gt;
 volatile uint8_t latest_interrupted_pin = 255;//whenever it isn&amp;#039;t 255 an interrupt has happened.&lt;br /&gt;
 volatile unsigned long hit_Time;&lt;br /&gt;
 unsigned long start_Time;&lt;br /&gt;
 unsigned long this_Time;&lt;br /&gt;
 byte first_hit;&lt;br /&gt;
 &lt;br /&gt;
 void setup() {&lt;br /&gt;
   delay(100);//Wait for display to power up.&lt;br /&gt;
   pinMode(gate0, INPUT_PULLUP);  //Enable internal pullup resistor--Photogate circuit will drive this input low.&lt;br /&gt;
   pinMode(gate1, INPUT_PULLUP);  //Enable internal pullup resistor--Photogate circuit will drive this input low.&lt;br /&gt;
   pinMode(gate2, INPUT_PULLUP);  //Enable internal pullup resistor--Photogate circuit will drive this input low.&lt;br /&gt;
   pinMode(gate3, INPUT_PULLUP);  //Enable internal pullup resistor--Photogate circuit will drive this input low.&lt;br /&gt;
   pinMode(gate4, INPUT_PULLUP);  //Enable internal pullup resistor--Photogate circuit will drive this input low.&lt;br /&gt;
   PCintPort::attachInterrupt(gate0, &amp;amp;interrupt_function, RISING);  //Watch the first gate.&lt;br /&gt;
   Wire.begin(); // join i2c bus (address optional for master)&lt;br /&gt;
   i2c_LCD_setup();&lt;br /&gt;
   i2c_LCD_display_waiting();&lt;br /&gt;
 }&lt;br /&gt;
 void loop() {&lt;br /&gt;
   switch (latest_interrupted_pin){&lt;br /&gt;
     case 255://no interrupt since last check&lt;br /&gt;
       break;&lt;br /&gt;
     case gate0:&lt;br /&gt;
       start_Time=hit_Time;&lt;br /&gt;
       i2c_LCD_display_tripped();&lt;br /&gt;
       first_hit=1;latest_interrupted_pin=255;&lt;br /&gt;
       PCintPort::attachInterrupt(gate1, &amp;amp;interrupt_function, RISING);&lt;br /&gt;
       PCintPort::attachInterrupt(gate2, &amp;amp;interrupt_function, RISING);&lt;br /&gt;
       PCintPort::attachInterrupt(gate3, &amp;amp;interrupt_function, RISING);&lt;br /&gt;
       PCintPort::attachInterrupt(gate4, &amp;amp;interrupt_function, RISING);&lt;br /&gt;
       break;&lt;br /&gt;
     case gate1:&lt;br /&gt;
       this_Time=hit_Time - start_Time;&lt;br /&gt;
       if (1==first_hit){&lt;br /&gt;
         clear_LCD(); first_hit=0;//this is the first gate tripped. Clear the waiting msg and reset our flag.&lt;br /&gt;
       }&lt;br /&gt;
       LCD_address_go(0);&lt;br /&gt;
       i2c_LCD_display_time();latest_interrupted_pin=255;&lt;br /&gt;
       break;&lt;br /&gt;
     case gate2:&lt;br /&gt;
       this_Time=hit_Time - start_Time;&lt;br /&gt;
       if (1==first_hit){&lt;br /&gt;
         clear_LCD(); first_hit=0;//this is the first gate tripped. Clear the waiting msg and reset our flag.&lt;br /&gt;
       }&lt;br /&gt;
       LCD_address_go(1);&lt;br /&gt;
       i2c_LCD_display_time();latest_interrupted_pin=255;&lt;br /&gt;
       break;&lt;br /&gt;
     case gate3:&lt;br /&gt;
       this_Time=hit_Time - start_Time;&lt;br /&gt;
       if (1==first_hit){&lt;br /&gt;
         clear_LCD(); first_hit=0;//this is the first gate tripped. Clear the waiting msg and reset our flag.&lt;br /&gt;
       }&lt;br /&gt;
       LCD_address_go(2);&lt;br /&gt;
       i2c_LCD_display_time();latest_interrupted_pin=255;&lt;br /&gt;
       break;&lt;br /&gt;
     case gate4:&lt;br /&gt;
       this_Time=hit_Time - start_Time;&lt;br /&gt;
       if (1==first_hit){&lt;br /&gt;
         clear_LCD(); first_hit=0;//this is the first gate tripped. Clear the waiting msg and reset our flag.&lt;br /&gt;
       }&lt;br /&gt;
       LCD_address_go(3);&lt;br /&gt;
       i2c_LCD_display_time();latest_interrupted_pin=255;&lt;br /&gt;
       break;&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
 void interrupt_function() {&lt;br /&gt;
   latest_interrupted_pin=PCintPort::arduinoPin;&lt;br /&gt;
   hit_Time = millis();&lt;br /&gt;
 }&lt;br /&gt;
 void i2c_LCD_display_tripped(){&lt;br /&gt;
   clear_LCD();&lt;br /&gt;
   Wire.beginTransmission(LCD_address);&lt;br /&gt;
   Wire.write(data_send);&lt;br /&gt;
   Wire.write(&amp;quot;1st gate tripped&amp;quot;);&lt;br /&gt;
   Wire.endTransmission();&lt;br /&gt;
 }&lt;br /&gt;
 void i2c_LCD_display_waiting(){&lt;br /&gt;
   clear_LCD();&lt;br /&gt;
   Wire.beginTransmission(LCD_address);&lt;br /&gt;
   Wire.write(data_send);&lt;br /&gt;
   Wire.write(&amp;quot;Waiting...&amp;quot;);&lt;br /&gt;
   Wire.endTransmission();&lt;br /&gt;
 }&lt;br /&gt;
 void i2c_LCD_display_time(){&lt;br /&gt;
   this_Time = this_Time * 8;//shift since we&amp;#039;re using 2MHz instead of 16MHz standard arduino crystal.&lt;br /&gt;
   //The above shift makes the milliseconds digit insignificant. For millisecond precision, use a 16MHz system&lt;br /&gt;
   Wire.beginTransmission(LCD_address);&lt;br /&gt;
   Wire.write(data_send);&lt;br /&gt;
   this_Time = this_Time % 100000;  //Ensure value is less than 100000&lt;br /&gt;
   Wire.write(48 + (this_Time / 10000));  //Print the 10000 digit&lt;br /&gt;
   this_Time = this_Time % 10000;  //Get rid of the 10000 digit&lt;br /&gt;
   Wire.write(48 + (this_Time / 1000));  //Print the 1000 digit&lt;br /&gt;
   Wire.write(&amp;quot;.&amp;quot;);&lt;br /&gt;
   this_Time = this_Time % 1000;  //Get rid of the 1000 digit&lt;br /&gt;
   Wire.write(48 + (this_Time / 100));  //Print the 100 digit&lt;br /&gt;
   this_Time = this_Time % 100;  //Get rid of the 100 digit&lt;br /&gt;
   Wire.write(48 + (this_Time / 10));  //Print the 10 digit&lt;br /&gt;
   /* See discussion above about precision. Uncomment if using 16MHz or precise system.&lt;br /&gt;
   this_Time = this_Time % 10;  //Get rid of the 10 digit&lt;br /&gt;
   Wire.write(48 + this_Time);  //Print the 1 digit&lt;br /&gt;
   */&lt;br /&gt;
   Wire.write(&amp;quot;s&amp;quot;);&lt;br /&gt;
   Wire.endTransmission();&lt;br /&gt;
 }&lt;br /&gt;
 void LCD_address_go(byte display_position){&lt;br /&gt;
   Wire.beginTransmission(LCD_address);&lt;br /&gt;
   Wire.write(command_send);&lt;br /&gt;
   switch (display_position){&lt;br /&gt;
     case 0:&lt;br /&gt;
       Wire.write(0x80);//data position byte is one bit followed by 7 for address&lt;br /&gt;
       break;&lt;br /&gt;
     case 1:&lt;br /&gt;
       Wire.write(0x88);//eighth data position, first line&lt;br /&gt;
       break;&lt;br /&gt;
     case 2:&lt;br /&gt;
       Wire.write(0xC0);//second line begins at 0x40 (plus 0x80 for data position command)&lt;br /&gt;
       break;&lt;br /&gt;
     case 3:&lt;br /&gt;
       Wire.write(0xC8);&lt;br /&gt;
       break;&lt;br /&gt;
   }&lt;br /&gt;
   Wire.endTransmission();&lt;br /&gt;
 }&lt;br /&gt;
 void i2c_LCD_setup(){&lt;br /&gt;
   Wire.beginTransmission(LCD_address);&lt;br /&gt;
   Wire.write(command_send);&lt;br /&gt;
   Wire.write(B00111000);  //FUNCTION SET 8 bit, 2 line, not double-height, 0, instruction set zero&lt;br /&gt;
   delay(20);&lt;br /&gt;
   Wire.write(B00111001);  //FUNCTION SET 8 bit, 2 line, not double-height, 0, instruction set one&lt;br /&gt;
   delay(20);&lt;br /&gt;
   Wire.write(B00010100);  //OSC set 1/5 bias, frequency last three bits&lt;br /&gt;
   Wire.write(B01111111);  //Contrast set, four least significant contrast bits&lt;br /&gt;
   Wire.write(B01011101);  //Power/ICON set, Icon on, booster on, two most significant contrast bits&lt;br /&gt;
   Wire.write(B01101101);  //FOLLOWER CONTROL, follower on, last three bits follower amp ratio&lt;br /&gt;
   delay(300);  //Allow new voltage to stabilize from previous command.&lt;br /&gt;
   Wire.write(B00111000);  //Back to instruction set zero&lt;br /&gt;
   Wire.write(B00001100);  //DISPLAY ON, display on, cursor off, cursor position off&lt;br /&gt;
   Wire.write(1);  //Clear display&lt;br /&gt;
   Wire.write(B00000110);  //ENTRY MODE, increment cursor, don&amp;#039;t shift display&lt;br /&gt;
   Wire.endTransmission();    // stop transmitting&lt;br /&gt;
 }&lt;br /&gt;
 void clear_LCD(){&lt;br /&gt;
   Wire.beginTransmission(LCD_address);&lt;br /&gt;
   Wire.write(command_send);&lt;br /&gt;
   Wire.write(1);  //Clear display&lt;br /&gt;
   Wire.endTransmission();    // stop transmitting&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
[[Category:Electronics]]&lt;/div&gt;</summary>
		<author><name>Shawn</name></author>
	</entry>
</feed>