# Slot car timer problems

**URL:** <https://forum.arduino.cc/t/slot-car-timer-problems/1055054>\
**Category:** Programming\
**Created:** [November 18, 2022, 2:59am UTC](https://forum.arduino.cc/t/slot-car-timer-problems/1055054 "2022-11-18T02:59:26Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [November 18, 2022, 8:32pm UTC](https://forum.arduino.cc/t/slot-car-timer-problems/1055054/21 "2022-11-18T20:32:52Z")

</div>

If you don't want to post code at all  
take a

## single

microcontroller that does it

## all

by using

## non-blocking timing

A teensy 4.1 will be fast enough with a CPU-clock of 600 Mhz and plenty of IO-pins

> **[Teensy 4.1 Entwicklungsboard ohne Stiftleisten](https://exp-tech.de/products/teensy-41-development-board)**
>
> Das Teensy 4.1 (TEENSY41) Development Board verfügt über einen ARM Cortex-M7-Prozessor mit 600 MHz. Die Maße betragen, wie beim Teensy 3.6, 6,1cm x 1,78cm. Im Teensy 4.1 ist derselbe Prozessor verbaut wie im Teensy 4.0, jedoch mit einer höheren...

---

<div class="post-metadata">

**Author:** ![shawnmart](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@shawnmart](https://forum.arduino.cc/u/shawnmart)\
**Post date:** [November 19, 2022, 12:02am UTC](https://forum.arduino.cc/t/slot-car-timer-problems/1055054/22 "2022-11-19T00:02:03Z")

</div>

I don’t have access to the code right now. Thanks for the help. I’ll post as soon as I can.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [November 19, 2022, 1:36am UTC](https://forum.arduino.cc/t/slot-car-timer-problems/1055054/23 "2022-11-19T01:36:00Z")

</div>

> [@shawnmart](#):
>
> I have tried the pin change interrupts but my problem is when the cars pass through the optocouplers the car breaks the beam and an interrupt occurs then the car leaves the beam and a second interrupt occurs.

There are different interrupt conditions.

> **[attachInterrupt() - Arduino Reference](https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/)**
>
> The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

> Parameters
> 
> `interrupt`: the number of the interrupt. Allowed data types: `int`.  
> `pin`: the Arduino pin number.  
> `ISR`: the ISR to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an interrupt service routine.  
> `mode`: defines when the interrupt should be triggered. Four constants are predefined as valid values:
> 
> - **LOW** to trigger the interrupt whenever the pin is low,
> - **CHANGE** to trigger the interrupt whenever the pin changes value
> - **RISING** to trigger when the pin goes from low to high,
> - **FALLING** for when the pin goes from high to low.

Note rising or falling edge.  
What trigger are you using?

Tom... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![dougp](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dougp/32/238908_2.png) [@dougp](https://forum.arduino.cc/u/dougp)\
**Post date:** [November 19, 2022, 2:01am UTC](https://forum.arduino.cc/t/slot-car-timer-problems/1055054/24 "2022-11-19T02:01:44Z")

</div>

> [@shawnmart](#):
>
> I have tried the pin change interrupts

Starting from an initial condition of all interrupts enabled - six total, correct?

When a car's leading edge generates its interrupt, record the time stamp then disable the interrupt for that sensor.&nbsp; When the race is over and all interrupts have been registered, reset to the initial condition.

What processor are you using?

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [November 19, 2022, 2:16am UTC](https://forum.arduino.cc/t/slot-car-timer-problems/1055054/25 "2022-11-19T02:16:14Z")

</div>

Hi,  
Can you post your code?  
Can you post a schematic of your project?  
Hand drawn and photographed is perfectly acceptable.  
Please include ALL hardware, component names and pin labels.

This will give us a platform to work on to help your situation.

An image(s) of your project setup would be good so we can see the beam setup.

Thanks.. Tom... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![shawnmart](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@shawnmart](https://forum.arduino.cc/u/shawnmart)\
**Post date:** [November 20, 2022, 10:45pm UTC](https://forum.arduino.cc/t/slot-car-timer-problems/1055054/26 "2022-11-20T22:45:32Z")

</div>

I can make it work using the falling interrupts but I would need 12 interrupts pins to have enough to read all of the sensors I need. Mega has 6 interrupt pins and two I will have to use for a I2c LCD display because they share the same pins as 2 of the interrupt pins. Wish they made a board where all pins could accept interrupts. I am writing the code now to post but the code is not the question that I have. My question is there a way to use the pin change interrupts in a way that are like the regular interrupts with a rising-falling condition.

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [November 20, 2022, 10:52pm UTC](https://forum.arduino.cc/t/slot-car-timer-problems/1055054/27 "2022-11-20T22:52:46Z")

</div>

> [@shawnmart](#):
>
> My question is there a way to use the pin change interrupts in a way that are like the regular interrupts

See [this article](https://playground.arduino.cc/Main/PinChangeInterrupt/) for the basics of pin change interrupt.

The trick, if we need to call it that, is to examine (within the interrupt service routine) all the pins that are on the vector for that port to see which pin, and which direction it went, was the cause of the interrupt.

HTH

a7

---

<div class="post-metadata">

**Author:** ![dougp](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dougp/32/238908_2.png) [@dougp](https://forum.arduino.cc/u/dougp)\
**Post date:** [November 21, 2022, 2:37am UTC](https://forum.arduino.cc/t/slot-car-timer-problems/1055054/28 "2022-11-21T02:37:10Z")

</div>

> [@shawnmart](#):
>
> My question is there a way to use the pin change interrupts in a way that are like the regular interrupts with a rising-falling condition.

See if this works for you:

> **[GitHub - NicoHood/PinChangeInterrupt: A simple & compact...](https://github.com/NicoHood/PinChangeInterrupt)**
>
> A simple & compact PinChangeInterrupt library for Arduino - GitHub - NicoHood/PinChangeInterrupt: A simple & compact PinChangeInterrupt library for Arduino

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [November 21, 2022, 3:19am UTC](https://forum.arduino.cc/t/slot-car-timer-problems/1055054/29 "2022-11-21T03:19:26Z")

</div>

Hi,  
Did you Google;

> arduino dragstrip timer

Tom.. 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 20, 2023, 3:19am UTC](https://forum.arduino.cc/t/slot-car-timer-problems/1055054/30 "2023-05-20T03:19:44Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

[Previous page](https://forum.arduino.cc/t/slot-car-timer-problems/1055054.md?page=1)
