31.07.2015 Views

A-Teachers-Guide-to-the-Intel-Galileo-Final

A-Teachers-Guide-to-the-Intel-Galileo-Final

A-Teachers-Guide-to-the-Intel-Galileo-Final

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A TEACHER’S GUIDE TO THE INTEL® GALILEO | 66}Serial.println(" unread mail(s).");if (tempCount != emailCount) // If it's a new value, update{ // Do this <strong>to</strong> prevent blinking <strong>the</strong> same #emailCount = tempCount; // update emailCount variabledigitalWrite(UNREAD_LED, HIGH); // turn <strong>the</strong> LED on}else if (tempCount == 0){digitalWrite(UNREAD_LED, LOW);}}// Bit of protection in case millis overruns:if (millis() < emailLastMillis)emailLastMillis = 0;// getEmailCount runs <strong>the</strong> unReadEmailChecker.py script, and reads <strong>the</strong> output.// It'll return <strong>the</strong> value printed by <strong>the</strong> unReadEmailChecker.py script.int getEmailCount(){int digits = 0;int temp[10];int emailCnt = 0;// Send a system call <strong>to</strong> run our python script and route <strong>the</strong>// output of <strong>the</strong> script <strong>to</strong> a file.system("python /home/root/decUnReadEmailChecker.py > /dev/ttyGS0");char line[100];FILE* emailsFile = fopen("/home/root/emails", "r");if (emailsFile) {// read from emails until we hit <strong>the</strong> end or a newlinewhile (fgets(line, 100, emailsFile) != NULL) {;}fclose(emailsFile);}else {Serial.println("No emails file created");}temp[digits++] = a<strong>to</strong>i(line); // convert string <strong>to</strong> an integersystem("rm emails"); // remove <strong>the</strong> file// Turn <strong>the</strong> individual digits in<strong>to</strong> a single integer:for (int i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!