tp_iot

Dependencies:   mbed DHT HC_SR04_Ultrasonic_Library

Committer:
Cornetin
Date:
Wed May 24 13:08:43 2017 +0000
Revision:
1:fdbb495760fc
Parent:
0:911000364564
Child:
2:d1555ccd1c6d
Adding serial connection with td1208

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Cornetin 0:911000364564 1 #include "mbed.h"
Cornetin 1:fdbb495760fc 2 #include "Serial.h"
Cornetin 1:fdbb495760fc 3 // WE USE PA_2 = TX } CN9
Cornetin 1:fdbb495760fc 4 // PA_3 = RX } CN9
Cornetin 1:fdbb495760fc 5
Cornetin 0:911000364564 6
Cornetin 0:911000364564 7 AnalogIn analog_value(A0);
Cornetin 0:911000364564 8
Cornetin 0:911000364564 9 DigitalOut led(LED1);
Cornetin 0:911000364564 10
Cornetin 0:911000364564 11 int main() {
Cornetin 0:911000364564 12 float meas;
Cornetin 1:fdbb495760fc 13 Serial serial_td1208(PA_2, PA_3);
Cornetin 1:fdbb495760fc 14
Cornetin 0:911000364564 15
Cornetin 0:911000364564 16 printf("\nAnalogIn example\n");
Cornetin 0:911000364564 17
Cornetin 0:911000364564 18 while(1) {
Cornetin 0:911000364564 19 meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
Cornetin 0:911000364564 20 meas = meas * 3300; // Change the value to be in the 0 to 3300 range
Cornetin 0:911000364564 21 printf("measure = %.0f mV\n", meas);
Cornetin 0:911000364564 22 if (meas > 2000) { // If the value is greater than 2V then switch the LED on
Cornetin 0:911000364564 23 led = 1;
Cornetin 0:911000364564 24 }
Cornetin 0:911000364564 25 else {
Cornetin 0:911000364564 26 led = 0;
Cornetin 0:911000364564 27 }
Cornetin 0:911000364564 28 wait(0.2); // 200 ms
Cornetin 0:911000364564 29 }
Cornetin 0:911000364564 30 }