The problem I am having is that when I view the Serial Monitor, the counter is increasing rapidly with no magnet present. I only want the counter to increase when a rising edge is detected. Instead, when I place a magnet near the hall sensor, the counter stops. It seems as if it is doing the opposite of what I want? Any suggestions?
Thank you!
I heard that Arduino had a built in pull up resistor on the digital pins, but I wasn't sure how to use it. That explains it.
Thanks again, you're a real help around here!
Your welcome, but you made it very easy by posting the revelant datasheet and posting your code. It takes some posters a long time to understand that the quality and usefulness of answers is directly proportional to the quality of their posting asking for the help.
I try and give as much info as possible. I figured I was probably just using some kind of feature of the Arduino improperly.
Just out of curiosity, would you happen to know if its possible to run a subroutine in the background? What I mean is, can you run the main task, and an alternate subroutine simultaneously? I would imagine constantly polling the hall sensor in the background isn't very efficient, but I would just like to try it anyways (rather than use an interrupt).
Well it's a single processor chip, so it never can do anything more then one machine instruction at a time. However 16mhz is faster then you might imagine and what may seem inefficient on paper can be duck soup for the chip.
Interrupts are a nice feature as you have used seen. There are also 'state machine' libraries that set up something that looks like multi-tasking, but really is polling via timed interrupts or polling inquires hidden from view.
I'm more proficient in hardware then software so you might hold out for other suggestions. Mine would be just get something running that performs the tasks you want done and later see if there might be a better way to structure the sketch. It's always better if you can post a sketch that either works or is close to working, then ask for ideas on improving it. And my rule is if runs without errors, does what I wanted done, then time to move on to the next project no matter how awkward the code may look on paper.