Created
October 3, 2013 22:09
-
-
Save nataliefreed/6817899 to your computer and use it in GitHub Desktop.
Example of using a single counter and the modulo operator (%) to time multiple events.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Natalie Freed, 10-3-2013 | |
Example of using a single counter and the modulo operator (%) to time multiple events. | |
For LWHS Building and Programming Intelligent Machines Fall 2013. | |
To use, open Serial Monitor to view output. | |
*/ | |
int counter = 0; | |
void setup() | |
{ | |
//start serial port | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
Serial.println("This line prints every second."); | |
if(counter % 3 == 0) //if counter is divisible by 3 (% is the remainder operator, called "modulo") | |
{ | |
Serial.println("This line prints every 3 seconds."); | |
} | |
if(counter % 5 == 0) //if counter is divisible by 5 (% is the remainder operator, called "modulo") | |
{ | |
Serial.println("This line prints every 5 seconds."); | |
} | |
delay(1000); //wait 1 second | |
counter = counter + 1; //increase counter by 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment