/* pfodUnoIRBasicMenus Control your IR Temperature Meter from your Android mobile see www.pfod.com.au for other projects (c)2013 Forward Computing and Control Pty. Ltd. This code may be freely used for both private and commerical use. Provide this copyright is maintained. NOTE: This sketch uses Interrupt 1 and pins D2,D3,D4 */ #include "pfodIRTemp.h" #include "pfodEEPROM.h" #include "pfodParser.h" pfodIRTemp irTemp; // construct class to handle sensor pfodParser parser; // construct the pfod cmd passer int lastTemperatureReading = 0; bool fahrenheit = false; // set to true for Farinheit instead of Celsius /** switch between Fahrenheit and Celsius */ void switchScale() { fahrenheit = !fahrenheit; // toggle from fahrenheit to celsius } // send the main menu based with last Temp Reading void sendMainMenu() { Serial.print(F("{" // start message ".")); // tell pfodApp this is a menu screen sendMainMenuWithLatestTemp(); } // send the update to main menu void sendMainMenuUpdate() { Serial.print(F("{" // start message ":")); // tell pfodApp this is an update to the existing menu screen sendMainMenuWithLatestTemp(); } void sendMainMenuWithLatestTemp() { Serial.print(F("IR Temperature Sensor" // display name of menu "`1000" // tell pfodApp to re-request again this menu after 1sec "|t~IR Temperature\n")); // first menu time temp + reading if (fahrenheit) { Serial.print(irTemp.convertToFahrenheit(lastTemperatureReading)); Serial.print(F("F")); } else { Serial.print(irTemp.convertToCelsius(lastTemperatureReading)); Serial.print(F("C")); } Serial.print(F("|c~Switch to\n")); // next menu item if (fahrenheit) { Serial.print(F("Celsius (C)")); } else { Serial.print(F("Fahrenheit (F)")); } Serial.print(F("|s~Show readings" // last menu item "}")); // close message } void setup() { Serial.begin(9600); for (int i = 3; i > 0; i--) { // wait a few secs to see if we are being programmed delay(1000); } parser.connect(&Serial); // connect the parser to the i/o stream } void loop() { byte cmd = parser.parse(); if (cmd != 0) { // got something if (cmd == '.') { // main menu request sendMainMenu(); } else if (cmd == 'c') { switchScale(); sendMainMenuUpdate(); } else if (cmd == 's') { // open Streaming Raw Data screen Serial.print(F("{=IR Temp Readings\n use BACK button to return\n to main menu}")); } else { // we don't handle message Serial.print(F("{}")); // BUT always respond or pfodApp will timeout } } irTemp.triggerSensor(); int reading = irTemp.getIRTemperature(); if (reading != pfodIRTemp::NO_DATA) { // have a reading Serial.print(millis() / 1000.0); // output secs since restart Serial.print(F(",Sec,")); // csv comma separator lastTemperatureReading = reading; // save reading for main menu if (reading < pfodIRTemp::NO_DATA) { Serial.println(F(" ,Invalid Reading")); } else { if (fahrenheit) { Serial.print(irTemp.convertToFahrenheit(reading)); Serial.println(F(",F")); } else { Serial.print(irTemp.convertToCelsius(reading)); Serial.println(F(",C")); } } } }