Sistema de monitoramento de controle e temperatura - GEPOC
Dependencies: DHT MODSERIAL ModbusSlave mbed
Fork of FRDM_RGBLED by
Revision 4:7bdab599ad88, committed 2016-03-18
- Comitter:
- nicolaselb
- Date:
- Fri Mar 18 13:14:02 2016 +0000
- Parent:
- 3:dd9b3bcbd36a
- Commit message:
- My 1st commit
Changed in this revision
diff -r dd9b3bcbd36a -r 7bdab599ad88 DHT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DHT.lib Fri Mar 18 13:14:02 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/nicolaselb/code/DHT/#1c743b3c7098
diff -r dd9b3bcbd36a -r 7bdab599ad88 GettingStarted.htm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GettingStarted.htm Fri Mar 18 13:14:02 2016 +0000 @@ -0,0 +1,1 @@ +<meta http-equiv="refresh" content="0; url=http://mbed.org/handbook/Getting-Started-mbed-Exporters#zip"/> \ No newline at end of file
diff -r dd9b3bcbd36a -r 7bdab599ad88 main.cpp --- a/main.cpp Mon Nov 09 18:59:28 2015 +0000 +++ b/main.cpp Fri Mar 18 13:14:02 2016 +0000 @@ -1,30 +1,19 @@ #include "mbed.h" #include <string.h> #include <stdio.h> - +#include "DHT.h" #include "ModbusSlave.h" - #include "MODSERIAL.h" MODSERIAL Modbus(USBTX,USBRX); -SPI myspi(PTD2, PTD3, PTD1); // mosi, miso, sclk - -//////////////// TERMOCOUPLERS ////////////////////////////// - -DigitalOut T1(PTC9); -DigitalOut T2(PTA13); -DigitalOut T3(PTD0); -DigitalOut T4(PTB3); +DigitalOut ENABLE(PTE0); -DigitalOut ENABLE(PTC1); - -//DigitalOut LED(LED_RED); +DigitalOut BUZZER(PTC1); +DigitalOut LED_VERM(PTC2); -float temp1 = 0; -float temp2 = 0; -float temp3 = 0; -float temp4 = 0; +DigitalOut RELE(PTB3); +DigitalOut LED_VERD(PTB2); //////////////// MODBUS Registers (Slave) /////////////////// @@ -32,10 +21,9 @@ { // just add or remove registers and your good to go... // The first register starts at address 0 - TERM_1, // Pot analog read - TERM_2, // Temp analog read - TERM_3, // Light analog read - TERM_4, // Moisture analog read + TEMP, // Pot analog read + UMID, // Temp analog read + DATA, HOLDING_REGS_SIZE // total number of registers for function 3 and 16 share the same register array }; @@ -45,58 +33,43 @@ //////////////////////////////////////////////////////////// - -uint16_t thermoparRead(void) -{ - uint16_t high = 0; - uint16_t low = 0; - - bool scToVcc; - bool scToGnd; - bool opened; - bool fail; - - high = ((myspi.write(0)<<8)&0xff00) + (myspi.write(0)&0x00ff); - low = ((myspi.write(0)<<8)&0xff00) + (myspi.write(0)&0x00ff); - - // Get errors from data - scToVcc = low & 0x0004; - scToGnd = low & 0x0002; - opened = low & 0x0001; - fail = high & 0x0001; - - if(opened) return 2; - if(fail) return 1; - return high&0xfffc; -} - +DHT sensor(PTB0,DHT22); +Timer t; int main() { //CONFIGURE MODBUS modbus_configure(&Modbus, 9600, 1, 2, &ENABLE, HOLDING_REGS_SIZE, holdingRegs); - + wait(1); + t.start(); while (true) { - modbus_update(); - - T1 = 0; - holdingRegs[TERM_1] = thermoparRead(); - T1 = 1; + modbus_update(); + + if(t.read() >= 5){ - T2 = 0; - holdingRegs[TERM_2] = thermoparRead(); - T2 = 1; + sensor.readData(); + holdingRegs[TEMP] = (int)(10*sensor.ReadTemperature(CELCIUS)); + holdingRegs[UMID] = (int)(10*sensor.ReadHumidity()); + + t.reset(); + + } - T3 = 0; - holdingRegs[TERM_3] = thermoparRead(); - T3 = 1; - - T4 = 0; - holdingRegs[TERM_4] = thermoparRead(); - T4 = 1; + int flag; + + flag = holdingRegs[DATA]; + + if (flag == 1){ + RELE = 0; + BUZZER = 1; + } else if(flag == 2){ + RELE = 1; + BUZZER = 0; + }else{ + BUZZER = 0; + RELE = 0; + } } -} - - - + +} \ No newline at end of file