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: MODSERIAL mbed-rtos mbed
Fork of Master by
main.cpp@3:12e1f116ea42, 2014-09-12 (annotated)
- Committer:
- 9uS7
- Date:
- Fri Sep 12 05:11:39 2014 +0000
- Revision:
- 3:12e1f116ea42
- Parent:
- 2:c610e1a7fbcd
- Child:
- 4:aaaadb45cbd9
hey
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
9uS7 | 0:4f07ba929908 | 1 | //Master mbed Program |
9uS7 | 0:4f07ba929908 | 2 | |
9uS7 | 0:4f07ba929908 | 3 | #include "mbed.h" |
9uS7 | 0:4f07ba929908 | 4 | #include "fm.h" |
9uS7 | 0:4f07ba929908 | 5 | #include "bluetooth.h" |
9uS7 | 1:e1cfb5850088 | 6 | #include "control.h" |
9uS7 | 0:4f07ba929908 | 7 | |
9uS7 | 1:e1cfb5850088 | 8 | //BT_MASTER or BT_SLAVE |
9uS7 | 1:e1cfb5850088 | 9 | #define DEVICE_ROLE BT_MASTER |
9uS7 | 0:4f07ba929908 | 10 | |
9uS7 | 1:e1cfb5850088 | 11 | Serial pc(USBTX, USBRX); // tx, rx |
9uS7 | 0:4f07ba929908 | 12 | |
9uS7 | 0:4f07ba929908 | 13 | //debug |
9uS7 | 0:4f07ba929908 | 14 | DigitalOut led1(LED1); |
9uS7 | 0:4f07ba929908 | 15 | DigitalOut led2(LED2); |
9uS7 | 0:4f07ba929908 | 16 | DigitalOut led4(LED4); |
9uS7 | 0:4f07ba929908 | 17 | |
9uS7 | 0:4f07ba929908 | 18 | DigitalOut myled1(LED1); |
9uS7 | 0:4f07ba929908 | 19 | DigitalOut myled2(LED2); |
9uS7 | 0:4f07ba929908 | 20 | |
9uS7 | 3:12e1f116ea42 | 21 | void masterLoop(void); |
9uS7 | 0:4f07ba929908 | 22 | |
9uS7 | 0:4f07ba929908 | 23 | int main() |
9uS7 | 0:4f07ba929908 | 24 | { |
9uS7 | 1:e1cfb5850088 | 25 | //FM_FREQUENCY is defined in fm.h |
9uS7 | 1:e1cfb5850088 | 26 | unsigned int fm_frequency = DEVICE_ROLE==BT_MASTER ? FM_FREQUENCY1 : FM_FREQUENCY2; |
9uS7 | 1:e1cfb5850088 | 27 | |
9uS7 | 3:12e1f116ea42 | 28 | //fmSetup( fm_frequency ); |
9uS7 | 1:e1cfb5850088 | 29 | btSetup(DEVICE_ROLE); |
9uS7 | 3:12e1f116ea42 | 30 | //motorSetup(); |
9uS7 | 2:c610e1a7fbcd | 31 | |
9uS7 | 0:4f07ba929908 | 32 | while(1){ |
9uS7 | 3:12e1f116ea42 | 33 | if( DEVICE_ROLE==BT_MASTER ){ |
9uS7 | 3:12e1f116ea42 | 34 | masterLoop(); |
9uS7 | 3:12e1f116ea42 | 35 | } |
9uS7 | 0:4f07ba929908 | 36 | /*i2c.start(); |
9uS7 | 0:4f07ba929908 | 37 | i2c.write(0x11); |
9uS7 | 0:4f07ba929908 | 38 | i2c.write(0x42); |
9uS7 | 0:4f07ba929908 | 39 | i2c.write(0x07); |
9uS7 | 0:4f07ba929908 | 40 | i2c.write(0x0F); |
9uS7 | 0:4f07ba929908 | 41 | i2c.stop(); |
9uS7 | 0:4f07ba929908 | 42 | wait(0.05);*/ |
9uS7 | 0:4f07ba929908 | 43 | } |
9uS7 | 0:4f07ba929908 | 44 | } |
9uS7 | 0:4f07ba929908 | 45 | |
9uS7 | 3:12e1f116ea42 | 46 | void masterLoop(){ |
9uS7 | 3:12e1f116ea42 | 47 | float ir_m,fsr_m; //sensor of master |
9uS7 | 3:12e1f116ea42 | 48 | float ir_s,fsr_s; //sensor of slave |
9uS7 | 3:12e1f116ea42 | 49 | sync(SYNC_SENSOR,NULL,NULL); |
9uS7 | 3:12e1f116ea42 | 50 | receiveSensor( &ir_s, &fsr_s ); |
9uS7 | 3:12e1f116ea42 | 51 | led1 = ( ir_s>0.5 ? 1 : 0 ); |
9uS7 | 3:12e1f116ea42 | 52 | wait(0.5); |
9uS7 | 3:12e1f116ea42 | 53 | } |