A wireless accelerometer based joypad using FRDM-KL25Z for the Gameduino based space invaders.
Dependencies: MMA8451Q mbed nRF2401A
Fork of nRF2401A_Hello_World by
nRF2401A connected to the KL25Z board:
main.cpp@0:8fcb46c5fa63, 2013-10-04 (annotated)
- Committer:
- TheChrisyd
- Date:
- Fri Oct 04 16:24:29 2013 +0000
- Revision:
- 0:8fcb46c5fa63
- Child:
- 2:440c95f796ac
First commit for week 1 update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TheChrisyd | 0:8fcb46c5fa63 | 1 | #include "mbed.h" |
TheChrisyd | 0:8fcb46c5fa63 | 2 | #include "nRF2401A.h" |
TheChrisyd | 0:8fcb46c5fa63 | 3 | |
TheChrisyd | 0:8fcb46c5fa63 | 4 | // comment these out depending on the job of the mbed. If your only using one mbed leave both uncommented. |
TheChrisyd | 0:8fcb46c5fa63 | 5 | #define TX |
TheChrisyd | 0:8fcb46c5fa63 | 6 | #define RX |
TheChrisyd | 0:8fcb46c5fa63 | 7 | |
TheChrisyd | 0:8fcb46c5fa63 | 8 | DigitalOut myled(LED1); |
TheChrisyd | 0:8fcb46c5fa63 | 9 | #ifdef TX |
TheChrisyd | 0:8fcb46c5fa63 | 10 | nRF2401A rf1(p10, p11, p12, p13, p14); |
TheChrisyd | 0:8fcb46c5fa63 | 11 | #endif |
TheChrisyd | 0:8fcb46c5fa63 | 12 | #ifdef RX |
TheChrisyd | 0:8fcb46c5fa63 | 13 | nRF2401A rf2(p21, p22, p23, p24, p25); |
TheChrisyd | 0:8fcb46c5fa63 | 14 | #endif |
TheChrisyd | 0:8fcb46c5fa63 | 15 | |
TheChrisyd | 0:8fcb46c5fa63 | 16 | Serial pc(USBTX, USBRX); |
TheChrisyd | 0:8fcb46c5fa63 | 17 | |
TheChrisyd | 0:8fcb46c5fa63 | 18 | int main() { |
TheChrisyd | 0:8fcb46c5fa63 | 19 | |
TheChrisyd | 0:8fcb46c5fa63 | 20 | wait(0.005); |
TheChrisyd | 0:8fcb46c5fa63 | 21 | |
TheChrisyd | 0:8fcb46c5fa63 | 22 | pc.printf("Hello nRF2401A\n\r"); |
TheChrisyd | 0:8fcb46c5fa63 | 23 | #ifdef TX |
TheChrisyd | 0:8fcb46c5fa63 | 24 | rf1.setDataPayloadLength(4 << 3) |
TheChrisyd | 0:8fcb46c5fa63 | 25 | .setAddress(0x0, 0x0, 0xa6, 0xa6, 0xa6, 3 << 3) |
TheChrisyd | 0:8fcb46c5fa63 | 26 | .setCRCMode(nRF2401A::NO_CRC) |
TheChrisyd | 0:8fcb46c5fa63 | 27 | .setDataRate(nRF2401A::BIT_RATE_250KBITS) |
TheChrisyd | 0:8fcb46c5fa63 | 28 | .setChannel(0x02); |
TheChrisyd | 0:8fcb46c5fa63 | 29 | |
TheChrisyd | 0:8fcb46c5fa63 | 30 | rf1.printControlPacket(pc); |
TheChrisyd | 0:8fcb46c5fa63 | 31 | |
TheChrisyd | 0:8fcb46c5fa63 | 32 | #endif |
TheChrisyd | 0:8fcb46c5fa63 | 33 | #ifdef RX |
TheChrisyd | 0:8fcb46c5fa63 | 34 | rf2.setDataPayloadLength(4 << 3) |
TheChrisyd | 0:8fcb46c5fa63 | 35 | .setAddress(0x0, 0x0, 0x53, 0x53, 0x53, 3 << 3) |
TheChrisyd | 0:8fcb46c5fa63 | 36 | .setCRCMode(nRF2401A::NO_CRC) |
TheChrisyd | 0:8fcb46c5fa63 | 37 | .setDataRate(nRF2401A::BIT_RATE_250KBITS) |
TheChrisyd | 0:8fcb46c5fa63 | 38 | .setChannel(0x02); |
TheChrisyd | 0:8fcb46c5fa63 | 39 | |
TheChrisyd | 0:8fcb46c5fa63 | 40 | rf2.printControlPacket(pc); |
TheChrisyd | 0:8fcb46c5fa63 | 41 | |
TheChrisyd | 0:8fcb46c5fa63 | 42 | #endif |
TheChrisyd | 0:8fcb46c5fa63 | 43 | #ifdef TX |
TheChrisyd | 0:8fcb46c5fa63 | 44 | rf1.flushControlPacket(); |
TheChrisyd | 0:8fcb46c5fa63 | 45 | #endif |
TheChrisyd | 0:8fcb46c5fa63 | 46 | #ifdef RX |
TheChrisyd | 0:8fcb46c5fa63 | 47 | rf2.flushControlPacket(); |
TheChrisyd | 0:8fcb46c5fa63 | 48 | #endif |
TheChrisyd | 0:8fcb46c5fa63 | 49 | #ifdef TX |
TheChrisyd | 0:8fcb46c5fa63 | 50 | nRF2401A::address_t rf2_addr = {0x0, 0x0, 0x53, 0x53, 0x53}; |
TheChrisyd | 0:8fcb46c5fa63 | 51 | uint8_t msg[] = {0x01, 0x01, 0x01, 0x01}; |
TheChrisyd | 0:8fcb46c5fa63 | 52 | uint32_t *msg32 = (uint32_t *) msg; |
TheChrisyd | 0:8fcb46c5fa63 | 53 | #endif |
TheChrisyd | 0:8fcb46c5fa63 | 54 | |
TheChrisyd | 0:8fcb46c5fa63 | 55 | while(1) { |
TheChrisyd | 0:8fcb46c5fa63 | 56 | #ifdef TX |
TheChrisyd | 0:8fcb46c5fa63 | 57 | rf1.sendMsg(rf2_addr, 3 << 3, msg, 4 << 3); |
TheChrisyd | 0:8fcb46c5fa63 | 58 | *msg32 += 1; |
TheChrisyd | 0:8fcb46c5fa63 | 59 | #endif |
TheChrisyd | 0:8fcb46c5fa63 | 60 | myled = 1; |
TheChrisyd | 0:8fcb46c5fa63 | 61 | wait(0.25); |
TheChrisyd | 0:8fcb46c5fa63 | 62 | #ifdef RX |
TheChrisyd | 0:8fcb46c5fa63 | 63 | rf2.printDataPacket(pc); |
TheChrisyd | 0:8fcb46c5fa63 | 64 | #endif |
TheChrisyd | 0:8fcb46c5fa63 | 65 | myled = 0; |
TheChrisyd | 0:8fcb46c5fa63 | 66 | wait(0.25); |
TheChrisyd | 0:8fcb46c5fa63 | 67 | } |
TheChrisyd | 0:8fcb46c5fa63 | 68 | } |