Switch monitor Project


I’m using a Adafruit Metro Mini 328 board. I’m monitoring the status of a switch on a truck and sending outputs to another device when the switch has been turned on.

My issue with this is the truck has been giving false “ON” and False “OFF”. I think there is interference on the line I’m monitoring. When the switch is OFF it must be getting voltage spikes causing the board to think the switch has been turned ON, Once it goes it away it Switches back OFF.

I’ve added delay and state detection in and it’s helped but still doesn’t seem like it solved the problem. I’m hoping someone can check out the code and make any suggestions that could help improve the way I’m doing this.

Find the code attached. Thanks in advance for any help at all!

PTO_5-26-16_latestREV.ino (2.57 KB)

If you put EVERY { on a line by itself, used Tools + Auto Format, and removed some of the useless white space, your code would be far easier to read.

You read the switch as many as 3 times, and then save the "current" state as the last state. Which of those 3 reads is the "current" state?