CRTI_Progs
/
XBee_sample
XBee-mbed sample
main.cpp@4:46e91d6f0b26, 2019-03-08 (annotated)
- Committer:
- bouaziz
- Date:
- Fri Mar 08 18:08:37 2019 +0000
- Revision:
- 4:46e91d6f0b26
- Parent:
- 2:505c58df1f94
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 0:12a6db2d1600 | 1 | #include "mbed.h" |
okini3939 | 0:12a6db2d1600 | 2 | #include "XBee.h" |
okini3939 | 0:12a6db2d1600 | 3 | |
bouaziz | 4:46e91d6f0b26 | 4 | BusIn joy(p15,p12,p13,p16); |
bouaziz | 4:46e91d6f0b26 | 5 | DigitalIn fire(p14); |
bouaziz | 4:46e91d6f0b26 | 6 | DigitalOut rstxbee(p30); |
bouaziz | 4:46e91d6f0b26 | 7 | |
okini3939 | 0:12a6db2d1600 | 8 | DigitalOut myled(LED1); |
bouaziz | 4:46e91d6f0b26 | 9 | Serial xbee(p9, p10); |
bouaziz | 4:46e91d6f0b26 | 10 | Serial pc(USBTX,USBRX); |
bouaziz | 4:46e91d6f0b26 | 11 | //XBeeAddress64 remoteAddress = XBeeAddress64(0x0013A200, 0x40319F25); |
okini3939 | 0:12a6db2d1600 | 12 | |
bouaziz | 4:46e91d6f0b26 | 13 | unsigned int vv; |
bouaziz | 4:46e91d6f0b26 | 14 | unsigned char nfire,ofire; |
okini3939 | 0:12a6db2d1600 | 15 | int main() { |
bouaziz | 4:46e91d6f0b26 | 16 | /* uint8_t Cmd[] = {'D', '4'}; |
okini3939 | 2:505c58df1f94 | 17 | uint8_t Low[] = {0x04}; |
okini3939 | 2:505c58df1f94 | 18 | uint8_t High[] = {0x05}; |
okini3939 | 0:12a6db2d1600 | 19 | RemoteAtCommandRequest remoteAtRequest; |
bouaziz | 4:46e91d6f0b26 | 20 | */ |
bouaziz | 4:46e91d6f0b26 | 21 | rstxbee=0; |
bouaziz | 4:46e91d6f0b26 | 22 | wait(0.001); |
bouaziz | 4:46e91d6f0b26 | 23 | rstxbee=1; |
bouaziz | 4:46e91d6f0b26 | 24 | wait(1.5); |
bouaziz | 4:46e91d6f0b26 | 25 | /* xbee.begin(9800); |
okini3939 | 0:12a6db2d1600 | 26 | |
okini3939 | 2:505c58df1f94 | 27 | remoteAtRequest = RemoteAtCommandRequest(remoteAddress, Cmd, Low, sizeof(Low)); |
okini3939 | 1:f9ececd7aa01 | 28 | remoteAtRequest.setApplyChanges(true); |
bouaziz | 4:46e91d6f0b26 | 29 | */ |
okini3939 | 0:12a6db2d1600 | 30 | while(1) { |
bouaziz | 4:46e91d6f0b26 | 31 | /* myled = 1; |
okini3939 | 2:505c58df1f94 | 32 | remoteAtRequest.setCommandValue(Low); |
okini3939 | 2:505c58df1f94 | 33 | remoteAtRequest.setCommandValueLength(sizeof(Low)); |
okini3939 | 0:12a6db2d1600 | 34 | xbee.send(remoteAtRequest); |
okini3939 | 0:12a6db2d1600 | 35 | myled = 0; |
okini3939 | 0:12a6db2d1600 | 36 | wait(1); |
okini3939 | 0:12a6db2d1600 | 37 | |
okini3939 | 0:12a6db2d1600 | 38 | myled = 1; |
okini3939 | 2:505c58df1f94 | 39 | remoteAtRequest.setCommandValue(High); |
okini3939 | 2:505c58df1f94 | 40 | remoteAtRequest.setCommandValueLength(sizeof(High)); |
okini3939 | 0:12a6db2d1600 | 41 | xbee.send(remoteAtRequest); |
okini3939 | 0:12a6db2d1600 | 42 | myled = 0; |
bouaziz | 4:46e91d6f0b26 | 43 | wait(1);*/ |
bouaziz | 4:46e91d6f0b26 | 44 | nfire = fire; |
bouaziz | 4:46e91d6f0b26 | 45 | wait(0.001); |
bouaziz | 4:46e91d6f0b26 | 46 | // pc.printf("VAL %u\t%u\n",(unsigned)nfire,(unsigned)ofire); |
bouaziz | 4:46e91d6f0b26 | 47 | if((ofire!=nfire)) { |
bouaziz | 4:46e91d6f0b26 | 48 | if(nfire==1){ |
bouaziz | 4:46e91d6f0b26 | 49 | xbee.printf("%u\r",vv); |
bouaziz | 4:46e91d6f0b26 | 50 | pc.printf("%u\r",vv); |
bouaziz | 4:46e91d6f0b26 | 51 | vv++; |
bouaziz | 4:46e91d6f0b26 | 52 | } |
bouaziz | 4:46e91d6f0b26 | 53 | ofire=nfire; |
bouaziz | 4:46e91d6f0b26 | 54 | |
bouaziz | 4:46e91d6f0b26 | 55 | } |
bouaziz | 4:46e91d6f0b26 | 56 | |
okini3939 | 0:12a6db2d1600 | 57 | } |
okini3939 | 0:12a6db2d1600 | 58 | } |