2 * Program: find out is the user typed in a leap year. The code assumes
3 * the user is not an idiot and only types in numbers that are a valid
5 * Author: Dr. Purdum, Aug. 7, 2012
13 if (Serial.available() > 0) {
17 bufferCount = ReadLine(myData);
19 Serial.print("Year: ");
21 if (IsLeapYear(year)) {
25 Serial.print(" is not ");
27 Serial.println("a leap year");
32 * Purpose: Determine if a given year is a leap year
38 * 1 if the year is a leap year, 0 otherwise
40 int IsLeapYear(int yr)
42 if (yr % 4 == 0 && yr % 100 != 0 || yr % 400 == 0) {
43 return 1; // It is a leap year
51 * Purpose: Read data from serial port until a newline character is read ('\n')
54 * character array that will be treated as a nul-terminated string
57 * the number of characters read for the string
58 * CAUTION: This method will sit here forever if no input is read from the serial
59 * port and no newline character is entered.
61 int ReadLine(char str[])
66 if (Serial.available() > 0) {
72 str[index] = '\0'; // null termination character