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.
Diff: main.cpp
- Revision:
- 1:d940df294833
- Parent:
- 0:a291f7cc08f8
- Child:
- 2:931f44b24aa4
--- a/main.cpp Mon May 15 09:37:02 2017 +0000 +++ b/main.cpp Tue May 23 10:14:45 2017 +0000 @@ -1,8 +1,15 @@ #include "mbed.h" #include "rtos.h" +#include "tHIH6130.h" #define SIG_RX_CAN 0x01 +#define I2C_SDA p28 +#define I2C_SCL p27 + +#define ADR_HIH 0x27 // adresse I2C réelle (sur 7 bits) + +I2C i2c(I2C_SDA , I2C_SCL ); DigitalOut led1(LED1); DigitalOut led2(LED2); @@ -14,9 +21,29 @@ CAN CanPort(p30, p29); CANMessage MessageRx; CANMessage MessageTx; +tHIH6130 Capteur(ADR_HIH,&i2c); +int flag=0; + unsigned int Id; +float mesureTemp(tHIH6130 Capteur) +{ + Capteur.StartMesure(); + wait_ms(50); + Capteur.UpdateData(); + float temp=Capteur.getTemp()/0.04; + return temp; +} + +float mesureHumi(tHIH6130 Capteur) +{ + Capteur.StartMesure(); + wait_ms(50); + Capteur.UpdateData(); + float humi=Capteur.getHumi()/0.025; + return humi; +} void canReader(void) { @@ -47,13 +74,9 @@ while (true) { led1 = !led1; - printf("TIC3s\n"); + printf("Envoi Temperature et Humidite \n"); MessageTx.id=Id; CanPort.write(MessageTx); - - if (Id < 0x3FF) Id++; - else Id = 0x000; - wait(3); } } @@ -62,12 +85,11 @@ int main() { + int temp=111; + int humi=111; CanPort.frequency(20000); - Id = 0x1A5; MessageTx.len=2; - MessageTx.data[0] = 0x55; - MessageTx.data[1] = 0xAA; MessageTx.format = CANStandard; //MessageTx.format = CANExtended; @@ -85,6 +107,21 @@ while (true) { - + if(flag==0) + { + temp=mesureTemp(Capteur); + Id = 0x032; + MessageTx.data[0]=temp/256; + MessageTx.data[1]=temp%256; + flag=1; + } + else + { + humi=mesureHumi(Capteur); + Id = 0x031; + MessageTx.data[0]=humi/256; + MessageTx.data[1]=humi%256; + flag=0; + } } }