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.
Dependencies: mbed
main.cpp@1:94681b7c2565, 2015-04-17 (annotated)
- Committer:
- Jamess
- Date:
- Fri Apr 17 13:01:00 2015 +0000
- Revision:
- 1:94681b7c2565
- Parent:
- 0:d3db149c4040
- Child:
- 2:769c937f9228
Falta apenas o :; Sleep e o ; Wake up;;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Jamess | 0:d3db149c4040 | 1 | // Goal: Program that receives and send 4 channels of data. |
| Jamess | 0:d3db149c4040 | 2 | // Receives: 1kHz |
| Jamess | 0:d3db149c4040 | 3 | // Sends: 70kbits/s |
| Jamess | 0:d3db149c4040 | 4 | // Ver qual o melhor modo de blueth (i2C,SPI,UART); |
| Jamess | 0:d3db149c4040 | 5 | /* DONE: |
| Jamess | 0:d3db149c4040 | 6 | Receber sinais Analógicos |
| Jamess | 0:d3db149c4040 | 7 | */ |
| Jamess | 0:d3db149c4040 | 8 | /* TO DO: |
| Jamess | 0:d3db149c4040 | 9 | Juntar ao módulo Bluetooth |
| Jamess | 0:d3db149c4040 | 10 | */ |
| Jamess | 0:d3db149c4040 | 11 | |
| Jamess | 0:d3db149c4040 | 12 | #include "mbed.h" |
| Jamess | 0:d3db149c4040 | 13 | |
| Jamess | 0:d3db149c4040 | 14 | /*------------Definição de Sinais--------------*/ |
| Jamess | 0:d3db149c4040 | 15 | |
| Jamess | 0:d3db149c4040 | 16 | #define ECG1 0 |
| Jamess | 0:d3db149c4040 | 17 | #define ECG2 1 |
| Jamess | 0:d3db149c4040 | 18 | #define RESP 2 |
| Jamess | 0:d3db149c4040 | 19 | #define PPG 3 |
| Jamess | 0:d3db149c4040 | 20 | |
| Jamess | 0:d3db149c4040 | 21 | /*-----READS THE ANALOG SIGNAL FROM THE SENSORS-----*/ |
| Jamess | 0:d3db149c4040 | 22 | |
| Jamess | 0:d3db149c4040 | 23 | AnalogIn Ecg1(A0); |
| Jamess | 0:d3db149c4040 | 24 | AnalogIn Ecg2(A1); |
| Jamess | 0:d3db149c4040 | 25 | AnalogIn Resp(A3); |
| Jamess | 0:d3db149c4040 | 26 | AnalogIn Ppg(A4); |
| Jamess | 0:d3db149c4040 | 27 | |
| Jamess | 0:d3db149c4040 | 28 | /*------CONTROLS THE DATA RATE OF THE READING------*/ |
| Jamess | 0:d3db149c4040 | 29 | Ticker t0; |
| Jamess | 0:d3db149c4040 | 30 | Serial pc(USBTX,USBRX); |
| Jamess | 0:d3db149c4040 | 31 | |
| Jamess | 1:94681b7c2565 | 32 | |
| Jamess | 0:d3db149c4040 | 33 | /*------HANDLES THE TIMER INTERRUPTIONS------------*/ |
| Jamess | 0:d3db149c4040 | 34 | |
| Jamess | 0:d3db149c4040 | 35 | void t0_handler(void); |
| Jamess | 0:d3db149c4040 | 36 | void rx_Handler(void); |
| Jamess | 1:94681b7c2565 | 37 | char test = 0; // Tests the data received from the computer in order to start the reading |
| Jamess | 1:94681b7c2565 | 38 | bool Valor=0; |
| Jamess | 0:d3db149c4040 | 39 | |
| Jamess | 0:d3db149c4040 | 40 | /*------------BUFFER TO STORE DATA------------------*/ |
| Jamess | 0:d3db149c4040 | 41 | |
| Jamess | 1:94681b7c2565 | 42 | int buffer[4] = {0,0,0,0}; |
| Jamess | 0:d3db149c4040 | 43 | |
| Jamess | 0:d3db149c4040 | 44 | |
| Jamess | 0:d3db149c4040 | 45 | |
| Jamess | 0:d3db149c4040 | 46 | int main() { |
| Jamess | 0:d3db149c4040 | 47 | pc.attach(&rx_Handler, pc.RxIrq); |
| Jamess | 1:94681b7c2565 | 48 | |
| Jamess | 1:94681b7c2565 | 49 | |
| Jamess | 1:94681b7c2565 | 50 | |
| Jamess | 0:d3db149c4040 | 51 | } |
| Jamess | 0:d3db149c4040 | 52 | |
| Jamess | 0:d3db149c4040 | 53 | /*----------------------FUNCTIONS-----------------------*/ |
| Jamess | 0:d3db149c4040 | 54 | |
| Jamess | 0:d3db149c4040 | 55 | //Reads and send data to the computer |
| Jamess | 0:d3db149c4040 | 56 | |
| Jamess | 0:d3db149c4040 | 57 | void t0_handler(void){ |
| Jamess | 1:94681b7c2565 | 58 | buffer[ECG1] = Ecg1.read_u16(); |
| Jamess | 1:94681b7c2565 | 59 | buffer[ECG2] = Ecg2.read_u16(); |
| Jamess | 1:94681b7c2565 | 60 | buffer[RESP] = Resp.read_u16(); |
| Jamess | 1:94681b7c2565 | 61 | buffer[PPG] = Ppg.read_u16(); |
| Jamess | 1:94681b7c2565 | 62 | pc.printf("%i,%i,%i,%i\n",buffer[ECG1],buffer[ECG2],buffer[RESP],buffer[PPG]); |
| Jamess | 0:d3db149c4040 | 63 | } |
| Jamess | 0:d3db149c4040 | 64 | |
| Jamess | 0:d3db149c4040 | 65 | //This function must |
| Jamess | 0:d3db149c4040 | 66 | |
| Jamess | 0:d3db149c4040 | 67 | void rx_Handler(void){ |
| Jamess | 1:94681b7c2565 | 68 | test = pc.getc(); // it gets the received character |
| Jamess | 1:94681b7c2565 | 69 | if (test=='s'|| test == 'S') |
| Jamess | 1:94681b7c2565 | 70 | { // wake up routine |
| Jamess | 1:94681b7c2565 | 71 | t0.attach(&t0_handler,0.001); //start counting ----Data read in a 1kHz freq. (1mS) |
| Jamess | 1:94681b7c2565 | 72 | return; |
| Jamess | 1:94681b7c2565 | 73 | }else if (test=='e'|| test == 'E') |
| Jamess | 1:94681b7c2565 | 74 | { |
| Jamess | 1:94681b7c2565 | 75 | t0.detach(); |
| Jamess | 1:94681b7c2565 | 76 | } |
| Jamess | 1:94681b7c2565 | 77 | |
| Jamess | 1:94681b7c2565 | 78 | } |