Dependencies:   mbed

Committer:
dmjanke
Date:
Wed Jan 07 20:42:00 2015 +0000
Revision:
7:ae30afe76643
Parent:
6:2ccd786cadd0
Clean up.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dmjanke 5:f453130cd6a7 1
Vanger 0:d9fd19c8ca39 2 #include "mbed.h"
Vanger 0:d9fd19c8ca39 3 #include "mtsas.h"
Vanger 0:d9fd19c8ca39 4
dmjanke 7:ae30afe76643 5 //Phone number to send to and receive from. Must be in the form "1xxxxxxxxxx"
dmjanke 7:ae30afe76643 6 string PHONE_NUMBER = "CHANGE ME PLEASE";
dmjanke 7:ae30afe76643 7
dmjanke 5:f453130cd6a7 8 DigitalOut heater(A1);
dmjanke 5:f453130cd6a7 9 AnalogIn sensor(A0);
dmjanke 5:f453130cd6a7 10 DigitalIn button(D5);
dmjanke 5:f453130cd6a7 11
dmjanke 5:f453130cd6a7 12 int main(void)
dmjanke 7:ae30afe76643 13 {
dmjanke 5:f453130cd6a7 14 printf("Breathalizer Starting ...\n\r");
Vanger 3:7fac2f012338 15
Vanger 3:7fac2f012338 16 //Sets the log level to INFO, higher log levels produce more log output.
Vanger 3:7fac2f012338 17 //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Vanger 1:1f5c9497a125 18 MTSLog::setLogLevel(MTSLog::INFO_LEVEL);
dmjanke 5:f453130cd6a7 19
Vanger 1:1f5c9497a125 20 Cellular::Sms txtmsg;
Vanger 1:1f5c9497a125 21 txtmsg.phoneNumber = PHONE_NUMBER;
Vanger 0:d9fd19c8ca39 22
dmjanke 7:ae30afe76643 23 if(PHONE_NUMBER == "CHANGE ME PLEASE") {
dmjanke 7:ae30afe76643 24 while(1) {
dmjanke 7:ae30afe76643 25 printf("FORGOT TO SET THE PHONE NUMBER\r\n");
dmjanke 7:ae30afe76643 26 wait(1.0f);
dmjanke 7:ae30afe76643 27 }
dmjanke 7:ae30afe76643 28 }
dmjanke 7:ae30afe76643 29
Vanger 0:d9fd19c8ca39 30 /** STMicro Nucelo F401RE
Vanger 0:d9fd19c8ca39 31 * The supported jumper configurations of the MTSAS do not line up with
Vanger 0:d9fd19c8ca39 32 * the pin mapping of the Nucleo F401RE. Therefore, the MTSAS serial TX
Vanger 0:d9fd19c8ca39 33 * pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2)
Vanger 0:d9fd19c8ca39 34 * and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to
Vanger 0:d9fd19c8ca39 35 * Serial1 TX (Shield pin D8).
Vanger 0:d9fd19c8ca39 36 * Uncomment the following line to use the STMicro Nuceleo F401RE
Vanger 0:d9fd19c8ca39 37 */
Vanger 0:d9fd19c8ca39 38 MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6);
dmjanke 5:f453130cd6a7 39
Vanger 4:ad889da9578c 40 //Sets the baud rate for communicating with the radio
Vanger 0:d9fd19c8ca39 41 io->baud(115200);
Vanger 0:d9fd19c8ca39 42
Vanger 2:d0d6e939ba70 43 //Creates a radio object
Vanger 0:d9fd19c8ca39 44 Cellular* radio = CellularFactory::create(io);
Vanger 2:d0d6e939ba70 45
Vanger 3:7fac2f012338 46 if (! radio) {
Vanger 3:7fac2f012338 47 logFatal("Failed to initialize radio");
Vanger 3:7fac2f012338 48 return 1;
Vanger 3:7fac2f012338 49 }
Vanger 3:7fac2f012338 50
dmjanke 5:f453130cd6a7 51 float value = 0.0f;
dmjanke 5:f453130cd6a7 52 heater = 0; //Active Low, 0 is turning it on.
dmjanke 5:f453130cd6a7 53 wait(0.1f);
dmjanke 5:f453130cd6a7 54
dmjanke 5:f453130cd6a7 55 // Waiting for the sensor to warm-up
dmjanke 5:f453130cd6a7 56 while(value > 0.001f) {
dmjanke 5:f453130cd6a7 57 wait(1.0f);
dmjanke 5:f453130cd6a7 58 value = 1.0f - sensor;
dmjanke 7:ae30afe76643 59 printf("Sensor is warming up : %2.2f\r\n", value);
Vanger 1:1f5c9497a125 60 }
dmjanke 5:f453130cd6a7 61
dmjanke 5:f453130cd6a7 62 printf("Sensor is warmed up!!! :-) \r\n");
dmjanke 5:f453130cd6a7 63
dmjanke 5:f453130cd6a7 64 while(1) {
dmjanke 5:f453130cd6a7 65 while(!button) {
dmjanke 5:f453130cd6a7 66 //Do Nothing
Vanger 1:1f5c9497a125 67 }
dmjanke 5:f453130cd6a7 68 printf("3\r\n");
dmjanke 5:f453130cd6a7 69 wait(1.0f);
dmjanke 5:f453130cd6a7 70 printf("2\r\n");
dmjanke 5:f453130cd6a7 71 wait(1.0f);
dmjanke 5:f453130cd6a7 72 printf("1\r\n");
dmjanke 5:f453130cd6a7 73 wait(1.0f);
dmjanke 5:f453130cd6a7 74 printf("BLOW!!!! :-)");
dmjanke 5:f453130cd6a7 75 wait(3.0f);
dmjanke 5:f453130cd6a7 76 value = 1.0f - sensor;
dmjanke 5:f453130cd6a7 77
dmjanke 5:f453130cd6a7 78 if (value > .8f) {
dmjanke 5:f453130cd6a7 79 txtmsg.message = "Get Uber Now! ;-)";
dmjanke 5:f453130cd6a7 80 } else if (value > .6f) {
dmjanke 5:f453130cd6a7 81 txtmsg.message = "Feeling Groovey";
dmjanke 5:f453130cd6a7 82 } else if (value > .4f) {
dmjanke 5:f453130cd6a7 83 txtmsg.message = "Have Another";
dmjanke 5:f453130cd6a7 84 } else {
dmjanke 5:f453130cd6a7 85 txtmsg.message = "Boooring";
dmjanke 5:f453130cd6a7 86 }
dmjanke 5:f453130cd6a7 87 printf("%s\n\r", txtmsg.message.c_str());
dmjanke 5:f453130cd6a7 88 printf("Sensor is: %2.2f\r\n", value);
dmjanke 5:f453130cd6a7 89
dmjanke 5:f453130cd6a7 90
dmjanke 5:f453130cd6a7 91 // Send SMS message to phone
dmjanke 5:f453130cd6a7 92 for (int i = 1; i < 10; i++) {
dmjanke 5:f453130cd6a7 93 if(radio->sendSMS(txtmsg) == MTS_SUCCESS) {
dmjanke 7:ae30afe76643 94 logInfo("Sent SMS successfully: <%s>\n", txtmsg.message.c_str());
dmjanke 5:f453130cd6a7 95 break;
dmjanke 5:f453130cd6a7 96 } else {
dmjanke 7:ae30afe76643 97 logError("Failed to send SMS: <%s>\n", txtmsg.message.c_str());
Vanger 1:1f5c9497a125 98 }
Vanger 1:1f5c9497a125 99 }
Vanger 1:1f5c9497a125 100 }
Vanger 0:d9fd19c8ca39 101 }