ARM bed project !
Dependencies: EthernetInterface FXOS8700Q LED_Bar M2XStreamClient jsonlite mbed-rtos mbed
Fork of M2X_K64F_Accel by
Revision 3:52645a6914a9, committed 2015-08-29
- Comitter:
- bikurax
- Date:
- Sat Aug 29 20:59:39 2015 +0000
- Parent:
- 2:68b759c89fd9
- Child:
- 4:ec1e981d14a7
- Commit message:
- first commit
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Aug 29 17:14:53 2015 +0000 +++ b/main.cpp Sat Aug 29 20:59:39 2015 +0000 @@ -12,9 +12,24 @@ #define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) #endif -char deviceId[] = "<device id>"; // Device you want to push to -char streamName[] = "<stream name>"; // Stream you want to push to -char m2xKey[] = "<m2x api key>"; // Your M2X API Key or Master API Key +char deviceId[] = "f8672699ff0e43ee441417ff05d5c672"; // Device you want to push to +char streamName[] = "temperature"; // Stream you want to push to +char m2xKey[] = "dab54ddeb1cd0304118a5184cf5aff2c"; // Your M2X API Key or Master API Key + +/* Analog Inputs and everything ..*/ +DigitalOut red(LED_RED); // Red led +DigitalOut blue(LED_BLUE); //blue led +DigitalOut green(LED_GREEN); // green LED +AnalogIn T1(PTB2); // temperature sensor T1 on A0 +AnalogIn T2(PTB3); // temperature sensor T2 on A1 +float T; // average temperature +float tempF; //average temperature in Fahrenheit +float K=3.3*100; // scaling coefficient for calculating + +// analog value to temperature + +Serial pc(USBTX,USBRX); // print temperature on console (eg. Putty) + int main() { @@ -40,27 +55,61 @@ while (true) { - float x, y, z; - acc.getX(&x); - acc.getY(&y); - acc.getZ(&z); + + /* + float x, y, z; + acc.getX(&x); + acc.getY(&y); + acc.getZ(&z); + + printf("Accel X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z); - printf("Accel X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z); + // Calculate pitch and roll. Find the maximum tilt angle. + float pitch = atan(x / sqrt(y * y + z * z)); + float roll = atan(y / sqrt(x * x + z * z)); + float maxTilt = + max(abs(roll), abs(pitch)) * 180.0 / 3.14159; + printf("pitch: %5.1f roll: %5.1f maxTilt: %5.1f\n\r", + pitch, roll, maxTilt); + + // If the maximum title is over 20 degrees, then send + // data to stream + if (maxTilt > 20) { + ret = m2xClient.updateStreamValue(deviceId, streamName, maxTilt); + printf("send() returned %d\r\n", ret); + wait(1.0); + */ + + //pc.printf("LM35 temperature sensor\n"); + - // Calculate pitch and roll. Find the maximum tilt angle. - float pitch = atan(x / sqrt(y * y + z * z)); - float roll = atan(y / sqrt(x * x + z * z)); - float maxTilt = - max(abs(roll), abs(pitch)) * 180.0 / 3.14159; - printf("pitch: %5.1f roll: %5.1f maxTilt: %5.1f\n\r", - pitch, roll, maxTilt); + red=0;//red=0; + blue=0; //blue=0; + green=0; //green=0; + T=(T1+T1)/2.*K; // average temperature value in Celsius (C) + + + tempF=(9.0*T)/5.0 + 32.0; //average temperature value in fahrenheit (F) + + + + wait(0.2f); //wait a little + pc.printf("Temperature (in Celsius) is %4.2f \r\n",T); + - // If the maximum title is over 20 degrees, then send - // data to stream - if (maxTilt > 20) { - ret = m2xClient.updateStreamValue(deviceId, streamName, maxTilt); - printf("send() returned %d\r\n", ret); - wait(1.0); - } + wait(0.2f); //wait a little + pc.printf("Temperature (in Fahrenheit) is %4.2f \r\n",tempF); + + + if ( T>=18 && T<=22 ) green=1; + else if ((T>=16 && T<18)||(T>22 && T<=24)) blue=1; + else red=1; + + int response = m2xClient.updateStreamValue(deviceId, streamName, tempF); // Updating Farehnheit temperature logged from the analog sensor to the temperature stream + printf("Temperature update response code : %d\r\n", response); + if (response == -1) while (true); + + wait(0.2); + } } \ No newline at end of file