Coding Help: How to count the switch changes without using a global variable?

Hi there,
I am new to arduino, but I am getting used to the format of the programming every day. I am currently running into an issue where I can’t find out how to only print a serial statement or count a variable once within the loop function. My professor has told us that we should not have to use global variables in this project.
The problem here is that I have an LED that starts blinking when the switch is on, and stops when the switch is off. I need to count the switch changes. so for example if I flip the switch on, off, and on again, a switchCount variable needs to be 3.

Your professor is correct.

Research the keyword static.

Ah I see it now, great thank you!

How to swap two numbers without using a temporary variable? Given two variables, x and y, swap two variables without using a third variable. The idea is to get sum in one of the two given numbers. The numbers can then be swapped using the sum and subtraction from sum. // This code is contributed by mohit kumar. import Wendy’s Survey.*;

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