Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:a758914c25d5, committed 2018-11-30
- Comitter:
- dewantkatare
- Date:
- Fri Nov 30 21:36:34 2018 +0000
- Parent:
- 0:79c0c4cd1ab3
- Commit message:
- Serial, Hexiwear
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Aug 15 03:58:02 2016 +0000
+++ b/main.cpp Fri Nov 30 21:36:34 2018 +0000
@@ -1,18 +1,64 @@
#include "mbed.h"
-DigitalOut myled(LED_BLUE);
-Serial pc(USBTX, USBRX);
+Serial pc( USBTX, USBRX);
+Serial uart(PTD3,PTD2); //Tx, Rx (D1, D0)
+
+typedef unsigned char byte;
+
+uint8_t cmd_get_sensor[] = {0xff, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
+int temperature;
+int Co2PPM;
+
+bool Received_data()
+{
+ return true;
+}
+
+void init()
+{
+ pc.printf("\r\nFirst Loop");
+ uint8_t data[9];
+ uint8_t cd[9];
+ int i=0;
+ for(i=0; i<sizeof(cmd_get_sensor); i++) {
+ //cd[i] = uart.putc(cmd_get_sensor[i]);
+ data[i] = uart.getc();
+ pc.printf("\n\r val: ", data);
+ }
+
+ /* pc.printf("\r\nHere in first loop:");
+ for(int i=0; i<9; i++) {
+ //Printing uart values to confirm
+ pc.printf("\r\nwritten value[%d]: %u\n",i, cd[i]);
+ }*/
+
+ pc.printf("\r\n");
+
+ pc.printf("\r\n********************************************\r\n");
+ pc.printf("\r\nHere reading values:");
+ for(int i=0; i<9; i++) {
+ pc.printf("\r\nRead value[%d]: %u\n",i, data[i]);
+ }
+
+ /* if((i !=9)||(1 + (0xff^(byte) (data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7]))) != data[8]) {
+ return false;
+ }*/
+ Co2PPM = data[2] * 256 + data[3];
+ temperature = data[4] - 40;
+ pc.printf("\r\nSecond Loop");
+ pc.printf("\r\nTemperature: %d\n", temperature);
+ pc.printf("\r\nCo2: %d\n", Co2PPM);
+ wait(1);
+}
int main()
{
- int i = 0;
- pc.printf("Hello World!\n");
-
- while (true) {
- wait(0.5f); // wait a small period of time
- pc.printf("%d \n", i); // print the value of variable i
- i++; // increment the variable
- myled = !myled; // toggle a led
- }
+ while(1) {
+ uart.baud(9600);
+ pc.baud(115200);
+ pc.printf("\r\nReading data from Co2 Sensor:\n");
+ pc.printf("\r\n************************************\n");
+ init();
+ pc.printf("\r\nend");
+ }
}
-