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
6 Author: Dr. Purdum, Aug. 7, 2012
16 if (Serial.available() > 0) {
22 bufferCount = ReadLine(myData);
23 year = atoi(myData); // Convert to int
24 Serial.print("Year: ");
26 if (IsLeapYear(year)) {
29 Serial.print(" is not ");
31 Serial.println("a leap year");
35 Purpose: Determine if a given year is a leap year
38 int yr The year to test
41 int 1 if the year is a leap year, 0 otherwise
43 int IsLeapYear(int yr)
45 if (yr % 4 == 0 && yr % 100 != 0 || yr % 400 == 0) {
46 return 1; // It is a leap year
48 return 0; // not a leap year
53 Purpose: Read data from serial port until a newline character is read ('\n')
56 char str[] character array that will be treated as a nul-terminated string
59 int the number of characters read for the string
61 CAUTION: This method will sit here forever if no input is read from the serial
62 port and no newline character is entered.
64 int ReadLine(char str[])
70 if (Serial.available() > 0) {
75 str[index] = '\0'; // null termination character