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 4DGL-uLCD-SE mbed-rtos nRF24L01P
main.cpp@41:9ed924a1f2e0, 2018-04-29 (annotated)
- Committer:
- jacksacane
- Date:
- Sun Apr 29 15:34:20 2018 +0000
- Revision:
- 41:9ed924a1f2e0
- Parent:
- 34:d73e95bbdbed
- Parent:
- 40:4f7d95c68d29
- Child:
- 44:a4f81588fcd5
Adds channel switching, fixes LCD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
drechtmann3 | 34:d73e95bbdbed | 1 | #include "uLCD_4DGL.h" |
Nurchu | 0:c35b54fb9c3c | 2 | #include "mbed.h" |
Nurchu | 7:0ac1f1ca8aa6 | 3 | #include "rtos.h" |
Nurchu | 20:e068469ffb89 | 4 | |
Nurchu | 2:dc046ff72566 | 5 | #include "Microphone.h" |
Nurchu | 20:e068469ffb89 | 6 | #include "Speaker.h" |
drechtmann3 | 18:e2a8ea6f55d3 | 7 | #include "HUD.h" |
Nurchu | 20:e068469ffb89 | 8 | #include "nRF24L01P.h" |
Nurchu | 20:e068469ffb89 | 9 | |
Nurchu | 20:e068469ffb89 | 10 | #include "CircularBuf.h" |
Nurchu | 20:e068469ffb89 | 11 | #include "CircularBuf.cpp" // Hack to get templates to work |
Nurchu | 20:e068469ffb89 | 12 | |
Nurchu | 27:08d34e60b6d0 | 13 | // How many times larger the buffer should be |
Nurchu | 33:5d86c111d9bc | 14 | #define FIFO_BUFFER_SCALE 250 |
Nurchu | 27:08d34e60b6d0 | 15 | // How maybe bytes to send over RF |
Nurchu | 27:08d34e60b6d0 | 16 | #define DATA_PACKET_SIZE 32 |
Nurchu | 27:08d34e60b6d0 | 17 | // How quickly to sample the mic / play the speaker |
jacksacane | 40:4f7d95c68d29 | 18 | #define SAMPLE_PERIOD 1/8000.0 |
Nurchu | 20:e068469ffb89 | 19 | |
Nurchu | 20:e068469ffb89 | 20 | |
Nurchu | 27:08d34e60b6d0 | 21 | Serial pc(USBTX, USBRX); |
Nurchu | 27:08d34e60b6d0 | 22 | DigitalOut myled1(LED1); // Mic data sent over RF |
Nurchu | 27:08d34e60b6d0 | 23 | DigitalOut myled2(LED2); // Speaker data recieved over RF |
Nurchu | 27:08d34e60b6d0 | 24 | DigitalOut myled3(LED3); // Sampled mic / played the speaker |
Nurchu | 27:08d34e60b6d0 | 25 | DigitalOut myled4(LED4); // Heartbeat |
Nurchu | 20:e068469ffb89 | 26 | |
Nurchu | 20:e068469ffb89 | 27 | Speaker spkr(p18); |
Nurchu | 27:08d34e60b6d0 | 28 | Microphone mic(p16); |
Nurchu | 27:08d34e60b6d0 | 29 | |
drechtmann3 | 34:d73e95bbdbed | 30 | uLCD_4DGL uLCD(p28, p27, p29); // serial tx, serial rx, reset pin; |
Nurchu | 20:e068469ffb89 | 31 | |
Nurchu | 20:e068469ffb89 | 32 | nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10); // mosi, miso, sck, csn, ce, irq |
Nurchu | 27:08d34e60b6d0 | 33 | CircularBuf<uint8_t> txbuff( FIFO_BUFFER_SCALE * DATA_PACKET_SIZE ); |
Nurchu | 27:08d34e60b6d0 | 34 | CircularBuf<uint8_t> rxbuff( FIFO_BUFFER_SCALE * DATA_PACKET_SIZE ); |
Nurchu | 27:08d34e60b6d0 | 35 | Ticker sampler; //10:41 am 4/20 |
Nurchu | 20:e068469ffb89 | 36 | |
Nurchu | 29:0c6f3c0c992a | 37 | InterruptIn button(p12); //changed DitialIn to InterruptIn at 5:54 4/18/18 |
jacksacane | 41:9ed924a1f2e0 | 38 | BusIn channel(p21, p22, p23, p24, p25); |
Nurchu | 20:e068469ffb89 | 39 | |
jacksacane | 21:95009b231c1f | 40 | int rfFreq; |
jacksacane | 21:95009b231c1f | 41 | int dataRate; |
jacksacane | 21:95009b231c1f | 42 | unsigned long long rxAddr, txAddr; |
jacksacane | 40:4f7d95c68d29 | 43 | int pipe = 0; |
jacksacane | 21:95009b231c1f | 44 | |
jacksacane | 21:95009b231c1f | 45 | enum operatingMode { |
jacksacane | 21:95009b231c1f | 46 | RECEIVE = 0, |
jacksacane | 21:95009b231c1f | 47 | TRANSMIT |
jacksacane | 21:95009b231c1f | 48 | }; |
jacksacane | 21:95009b231c1f | 49 | |
jacksacane | 21:95009b231c1f | 50 | operatingMode mode; |
jacksacane | 21:95009b231c1f | 51 | |
Nurchu | 27:08d34e60b6d0 | 52 | // Cheap nonbranching min function |
Nurchu | 27:08d34e60b6d0 | 53 | int min(int a, int b) { |
Nurchu | 27:08d34e60b6d0 | 54 | return a * (int)(a <= b) + b * (int)(b < a); |
Nurchu | 27:08d34e60b6d0 | 55 | } |
drechtmann3 | 1:fc0a2c17e086 | 56 | |
jacksacane | 40:4f7d95c68d29 | 57 | // Sets the channel of the RF device based on which swtiches are flipped |
jacksacane | 40:4f7d95c68d29 | 58 | // by changing RX/TX pipes |
Nurchu | 27:08d34e60b6d0 | 59 | // TODO: Make sure we don't have to restart the device or anything to change this |
jacksacane | 40:4f7d95c68d29 | 60 | void setChannel() { |
jacksacane | 41:9ed924a1f2e0 | 61 | int oldPipe = pipe; |
jacksacane | 41:9ed924a1f2e0 | 62 | int width = 5; |
jacksacane | 40:4f7d95c68d29 | 63 | switch (channel) { |
jacksacane | 40:4f7d95c68d29 | 64 | case 0: // Channel 0 |
jacksacane | 41:9ed924a1f2e0 | 65 | rxAddr = txAddr = 0xC2C2C2C2C0; |
jacksacane | 40:4f7d95c68d29 | 66 | pipe = NRF24L01P_PIPE_P0; |
jacksacane | 41:9ed924a1f2e0 | 67 | if (pipe != oldPipe) { |
jacksacane | 41:9ed924a1f2e0 | 68 | my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 41:9ed924a1f2e0 | 69 | my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 41:9ed924a1f2e0 | 70 | } |
jacksacane | 40:4f7d95c68d29 | 71 | break; |
jacksacane | 40:4f7d95c68d29 | 72 | case 1: // Channel 1 |
jacksacane | 40:4f7d95c68d29 | 73 | rxAddr = txAddr = 0xC2C2C2C2C1; |
jacksacane | 40:4f7d95c68d29 | 74 | pipe = NRF24L01P_PIPE_P1; |
jacksacane | 41:9ed924a1f2e0 | 75 | if (pipe != oldPipe) { |
jacksacane | 41:9ed924a1f2e0 | 76 | my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 41:9ed924a1f2e0 | 77 | my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 41:9ed924a1f2e0 | 78 | } |
jacksacane | 40:4f7d95c68d29 | 79 | break; |
jacksacane | 40:4f7d95c68d29 | 80 | case 2: // Channel 2 |
jacksacane | 40:4f7d95c68d29 | 81 | rxAddr = txAddr = 0xC2C2C2C2C2; |
jacksacane | 40:4f7d95c68d29 | 82 | pipe = NRF24L01P_PIPE_P2; |
jacksacane | 41:9ed924a1f2e0 | 83 | if (pipe != oldPipe) { |
jacksacane | 41:9ed924a1f2e0 | 84 | my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 41:9ed924a1f2e0 | 85 | my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 41:9ed924a1f2e0 | 86 | } |
jacksacane | 40:4f7d95c68d29 | 87 | break; |
jacksacane | 40:4f7d95c68d29 | 88 | case 4: // Channel 3 |
jacksacane | 40:4f7d95c68d29 | 89 | rxAddr = txAddr = 0xC2C2C2C2C3; |
jacksacane | 40:4f7d95c68d29 | 90 | pipe = NRF24L01P_PIPE_P3; |
jacksacane | 41:9ed924a1f2e0 | 91 | if (pipe != oldPipe) { |
jacksacane | 41:9ed924a1f2e0 | 92 | my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 41:9ed924a1f2e0 | 93 | my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 41:9ed924a1f2e0 | 94 | } |
jacksacane | 40:4f7d95c68d29 | 95 | break; |
jacksacane | 40:4f7d95c68d29 | 96 | case 8: // Channel 4 |
jacksacane | 40:4f7d95c68d29 | 97 | rxAddr = txAddr = 0xC2C2C2C2C4; |
jacksacane | 40:4f7d95c68d29 | 98 | pipe = NRF24L01P_PIPE_P4; |
jacksacane | 41:9ed924a1f2e0 | 99 | if (pipe != oldPipe) { |
jacksacane | 41:9ed924a1f2e0 | 100 | my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 41:9ed924a1f2e0 | 101 | my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 41:9ed924a1f2e0 | 102 | } |
jacksacane | 40:4f7d95c68d29 | 103 | break; |
jacksacane | 40:4f7d95c68d29 | 104 | case 16: // Channel 5 |
jacksacane | 40:4f7d95c68d29 | 105 | rxAddr = txAddr = 0xC2C2C2C2C5; |
jacksacane | 40:4f7d95c68d29 | 106 | pipe = NRF24L01P_PIPE_P5; |
jacksacane | 41:9ed924a1f2e0 | 107 | if (pipe != oldPipe) { |
jacksacane | 41:9ed924a1f2e0 | 108 | my_nrf24l01p.setRxAddress(rxAddr, width, pipe); |
jacksacane | 41:9ed924a1f2e0 | 109 | my_nrf24l01p.setTxAddress(txAddr, width); |
jacksacane | 41:9ed924a1f2e0 | 110 | } |
jacksacane | 40:4f7d95c68d29 | 111 | break; |
jacksacane | 40:4f7d95c68d29 | 112 | default: |
jacksacane | 40:4f7d95c68d29 | 113 | break; |
jacksacane | 40:4f7d95c68d29 | 114 | } |
Nurchu | 27:08d34e60b6d0 | 115 | |
jacksacane | 40:4f7d95c68d29 | 116 | //pc.printf("Pipe = %d\r\n", pipe); |
jacksacane | 40:4f7d95c68d29 | 117 | |
Nurchu | 27:08d34e60b6d0 | 118 | // TODO: Don't force it to the default RF frequency |
jacksacane | 40:4f7d95c68d29 | 119 | //channelNum = 2; |
Nurchu | 27:08d34e60b6d0 | 120 | |
jacksacane | 40:4f7d95c68d29 | 121 | //my_nrf24l01p.setRfFrequency(channelNum + NRF24L01P_MIN_RF_FREQUENCY); |
Nurchu | 27:08d34e60b6d0 | 122 | } |
drechtmann3 | 1:fc0a2c17e086 | 123 | |
Nurchu | 27:08d34e60b6d0 | 124 | // Callback interrupt from the button to shift into transmit mode |
Nurchu | 27:08d34e60b6d0 | 125 | void enterTransmitMode() { |
Nurchu | 27:08d34e60b6d0 | 126 | mode = TRANSMIT; |
Nurchu | 33:5d86c111d9bc | 127 | txbuff.clear(); |
Nurchu | 27:08d34e60b6d0 | 128 | } |
drechtmann3 | 1:fc0a2c17e086 | 129 | |
Nurchu | 27:08d34e60b6d0 | 130 | // Callback interrupt from the button to shift into receive mode |
Nurchu | 27:08d34e60b6d0 | 131 | void enterRecieveMode() { |
Nurchu | 27:08d34e60b6d0 | 132 | mode = RECEIVE; |
drechtmann3 | 34:d73e95bbdbed | 133 | rxbuff.clear(); |
drechtmann3 | 10:a8fcfc869fa5 | 134 | } |
drechtmann3 | 1:fc0a2c17e086 | 135 | |
Nurchu | 27:08d34e60b6d0 | 136 | // Called every SAMPLE_PERIOD ms to sample the mic or output data into the speaker |
Nurchu | 27:08d34e60b6d0 | 137 | void sampleData() |
Nurchu | 12:efcfe4c0d9f2 | 138 | { |
Nurchu | 27:08d34e60b6d0 | 139 | // Depending on the mode, only sample the mic or output data to the speaker |
Nurchu | 27:08d34e60b6d0 | 140 | if (mode == RECEIVE) { |
Nurchu | 27:08d34e60b6d0 | 141 | // Get speaker sample from buffer |
Nurchu | 27:08d34e60b6d0 | 142 | // If there is no data in the buffer, it will just output 0 to the write function |
Nurchu | 27:08d34e60b6d0 | 143 | uint8_t speakerSample = 0; |
Nurchu | 27:08d34e60b6d0 | 144 | rxbuff.pop(&speakerSample, 1); |
Nurchu | 27:08d34e60b6d0 | 145 | |
Nurchu | 27:08d34e60b6d0 | 146 | // Output into the actual speaker |
Nurchu | 27:08d34e60b6d0 | 147 | spkr.write(speakerSample); |
Nurchu | 27:08d34e60b6d0 | 148 | } else { |
Nurchu | 27:08d34e60b6d0 | 149 | // Get mic sample and place into buffer |
Nurchu | 33:5d86c111d9bc | 150 | uint8_t micSample = mic.getData(); |
Nurchu | 27:08d34e60b6d0 | 151 | txbuff.push(&micSample, 1); |
Nurchu | 12:efcfe4c0d9f2 | 152 | |
Nurchu | 27:08d34e60b6d0 | 153 | // Make sure the speaker is actually off |
Nurchu | 27:08d34e60b6d0 | 154 | spkr.turnOff(); |
Nurchu | 27:08d34e60b6d0 | 155 | } |
Nurchu | 27:08d34e60b6d0 | 156 | |
Nurchu | 27:08d34e60b6d0 | 157 | // TODO: This will have to be removed later on once we actually crank up the sample rate |
Nurchu | 27:08d34e60b6d0 | 158 | myled3 = !myled3; |
Nurchu | 27:08d34e60b6d0 | 159 | } |
drechtmann3 | 1:fc0a2c17e086 | 160 | |
Nurchu | 27:08d34e60b6d0 | 161 | // Communicates to the other MBED using RF |
Nurchu | 27:08d34e60b6d0 | 162 | void commThread() |
Nurchu | 27:08d34e60b6d0 | 163 | { |
Nurchu | 27:08d34e60b6d0 | 164 | // We want this in it's own thread so we don't have to worry about the |
Nurchu | 27:08d34e60b6d0 | 165 | // timings screwing anything else up |
Nurchu | 27:08d34e60b6d0 | 166 | // It can't be in an interrupt because of that |
Nurchu | 27:08d34e60b6d0 | 167 | while (true) { |
Nurchu | 27:08d34e60b6d0 | 168 | // Change what we are sending based on what mode we are in |
Nurchu | 27:08d34e60b6d0 | 169 | if (mode == RECEIVE) { |
Nurchu | 27:08d34e60b6d0 | 170 | // Make sure something is there to read |
Nurchu | 27:08d34e60b6d0 | 171 | if (my_nrf24l01p.readable( NRF24L01P_PIPE_P0 )) { |
Nurchu | 27:08d34e60b6d0 | 172 | uint8_t spkrPacket[DATA_PACKET_SIZE]; |
Nurchu | 27:08d34e60b6d0 | 173 | |
Nurchu | 27:08d34e60b6d0 | 174 | // Remove entire packet of data from the bus |
Nurchu | 27:08d34e60b6d0 | 175 | int numReceived = my_nrf24l01p.read( NRF24L01P_PIPE_P0, (char*) spkrPacket, DATA_PACKET_SIZE ); |
Nurchu | 27:08d34e60b6d0 | 176 | |
Nurchu | 27:08d34e60b6d0 | 177 | // Place into buffer to play speaker in another thread |
Nurchu | 27:08d34e60b6d0 | 178 | // Only place into the buffer the number of bytes received |
Nurchu | 27:08d34e60b6d0 | 179 | rxbuff.push(spkrPacket, min(DATA_PACKET_SIZE, numReceived)); |
Nurchu | 27:08d34e60b6d0 | 180 | |
jacksacane | 40:4f7d95c68d29 | 181 | //pc.printf("Receiviing....\n\r"); |
Nurchu | 27:08d34e60b6d0 | 182 | myled2 = !myled2; |
Nurchu | 27:08d34e60b6d0 | 183 | } |
Nurchu | 27:08d34e60b6d0 | 184 | } else { // mode == TRANSMIT |
Nurchu | 27:08d34e60b6d0 | 185 | if (txbuff.size() >= DATA_PACKET_SIZE) { |
Nurchu | 27:08d34e60b6d0 | 186 | uint8_t micPacket[DATA_PACKET_SIZE]; |
Nurchu | 27:08d34e60b6d0 | 187 | |
Nurchu | 27:08d34e60b6d0 | 188 | // Pull an entire packet of data from the mic sample buffer |
Nurchu | 27:08d34e60b6d0 | 189 | int numPopped = txbuff.pop(micPacket, DATA_PACKET_SIZE); |
drechtmann3 | 34:d73e95bbdbed | 190 | // rxbuff.push(micPacket, DATA_PACKET_SIZE); |
Nurchu | 27:08d34e60b6d0 | 191 | |
Nurchu | 27:08d34e60b6d0 | 192 | // Send the entire buffer to the other device |
Nurchu | 27:08d34e60b6d0 | 193 | // TODO: We just assume that DATA_PACKET_SIZE bytes were popped, this may |
Nurchu | 27:08d34e60b6d0 | 194 | // not be the case |
Nurchu | 27:08d34e60b6d0 | 195 | my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char*) micPacket, DATA_PACKET_SIZE ); |
drechtmann3 | 34:d73e95bbdbed | 196 | |
Nurchu | 27:08d34e60b6d0 | 197 | myled1 = !myled1; |
Nurchu | 27:08d34e60b6d0 | 198 | } |
drechtmann3 | 1:fc0a2c17e086 | 199 | } |
Nurchu | 27:08d34e60b6d0 | 200 | |
Nurchu | 33:5d86c111d9bc | 201 | //pc.printf("TX Size %d RX Size%d Mode %d\n\r", txbuff.size(), rxbuff.size(), mode); |
Nurchu | 27:08d34e60b6d0 | 202 | Thread::yield(); |
Nurchu | 33:5d86c111d9bc | 203 | //Thread::wait(10); |
Nurchu | 12:efcfe4c0d9f2 | 204 | } |
Nurchu | 12:efcfe4c0d9f2 | 205 | } |
drechtmann3 | 1:fc0a2c17e086 | 206 | |
Nurchu | 27:08d34e60b6d0 | 207 | // Displays the current info to the LCD display |
jacksacane | 21:95009b231c1f | 208 | void lcdThread() |
jacksacane | 21:95009b231c1f | 209 | { |
jacksacane | 21:95009b231c1f | 210 | while (1) { |
drechtmann3 | 34:d73e95bbdbed | 211 | uLCD.locate(0, 0); |
jacksacane | 41:9ed924a1f2e0 | 212 | uLCD.printf("Freq: %d MHz", rfFreq); |
drechtmann3 | 34:d73e95bbdbed | 213 | uLCD.locate(0, 2); |
jacksacane | 41:9ed924a1f2e0 | 214 | uLCD.printf("Rate: %d kbps", dataRate); |
drechtmann3 | 34:d73e95bbdbed | 215 | uLCD.locate(0, 4); |
jacksacane | 41:9ed924a1f2e0 | 216 | uLCD.printf("TX: 0x%010llX", txAddr); |
drechtmann3 | 34:d73e95bbdbed | 217 | uLCD.locate(0, 6); |
jacksacane | 41:9ed924a1f2e0 | 218 | uLCD.printf("RX: 0x%010llX", rxAddr); |
drechtmann3 | 34:d73e95bbdbed | 219 | uLCD.locate(0, 8); |
Nurchu | 27:08d34e60b6d0 | 220 | |
jacksacane | 21:95009b231c1f | 221 | switch (mode) { |
jacksacane | 21:95009b231c1f | 222 | case RECEIVE: |
jacksacane | 41:9ed924a1f2e0 | 223 | uLCD.printf("Mode: Receiving"); |
jacksacane | 21:95009b231c1f | 224 | break; |
jacksacane | 21:95009b231c1f | 225 | case TRANSMIT: |
jacksacane | 21:95009b231c1f | 226 | uLCD.printf("Mode: Transmitting"); |
jacksacane | 21:95009b231c1f | 227 | break; |
jacksacane | 21:95009b231c1f | 228 | } |
drechtmann3 | 34:d73e95bbdbed | 229 | |
jacksacane | 21:95009b231c1f | 230 | // Maybe add some graphics too idk |
Nurchu | 33:5d86c111d9bc | 231 | Thread::wait(500); |
jacksacane | 21:95009b231c1f | 232 | } |
jacksacane | 21:95009b231c1f | 233 | } |
jacksacane | 21:95009b231c1f | 234 | |
Nurchu | 12:efcfe4c0d9f2 | 235 | int main() |
Nurchu | 12:efcfe4c0d9f2 | 236 | { |
Nurchu | 27:08d34e60b6d0 | 237 | Thread lcd; |
Nurchu | 27:08d34e60b6d0 | 238 | Thread comm; |
jacksacane | 21:95009b231c1f | 239 | |
Nurchu | 27:08d34e60b6d0 | 240 | // Set up the nrf24l01p |
jacksacane | 41:9ed924a1f2e0 | 241 | my_nrf24l01p.setAirDataRate(2000); // 2Mbs |
jacksacane | 21:95009b231c1f | 242 | rfFreq = my_nrf24l01p.getRfFrequency(); |
jacksacane | 21:95009b231c1f | 243 | dataRate = my_nrf24l01p.getAirDataRate(); |
jacksacane | 21:95009b231c1f | 244 | rxAddr = my_nrf24l01p.getRxAddress(); |
jacksacane | 21:95009b231c1f | 245 | txAddr = my_nrf24l01p.getTxAddress(); |
jacksacane | 21:95009b231c1f | 246 | |
Nurchu | 27:08d34e60b6d0 | 247 | my_nrf24l01p.setTransferSize(DATA_PACKET_SIZE); |
jacksacane | 21:95009b231c1f | 248 | |
jacksacane | 21:95009b231c1f | 249 | my_nrf24l01p.setReceiveMode(); |
jacksacane | 21:95009b231c1f | 250 | my_nrf24l01p.enable(); |
jacksacane | 21:95009b231c1f | 251 | |
jacksacane | 40:4f7d95c68d29 | 252 | pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", rfFreq ); |
jacksacane | 40:4f7d95c68d29 | 253 | pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); |
jacksacane | 40:4f7d95c68d29 | 254 | pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); |
jacksacane | 40:4f7d95c68d29 | 255 | pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", txAddr ); |
jacksacane | 40:4f7d95c68d29 | 256 | pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", rxAddr ); |
jacksacane | 40:4f7d95c68d29 | 257 | |
Nurchu | 27:08d34e60b6d0 | 258 | pc.printf("Finished starting up....\n\r"); |
Nurchu | 27:08d34e60b6d0 | 259 | |
jacksacane | 22:e835b3490280 | 260 | mode = RECEIVE; |
jacksacane | 22:e835b3490280 | 261 | |
jacksacane | 21:95009b231c1f | 262 | // Initialize the uLCD |
drechtmann3 | 34:d73e95bbdbed | 263 | uLCD.baudrate(3000000); |
drechtmann3 | 34:d73e95bbdbed | 264 | uLCD.background_color(BLACK); |
jacksacane | 21:95009b231c1f | 265 | |
jacksacane | 21:95009b231c1f | 266 | // Spawn threads |
jacksacane | 21:95009b231c1f | 267 | lcd.start(lcdThread); |
Nurchu | 27:08d34e60b6d0 | 268 | comm.start(commThread); |
jacksacane | 21:95009b231c1f | 269 | |
Nurchu | 27:08d34e60b6d0 | 270 | // Setup the button to enter transmit mode when pushed down |
Nurchu | 27:08d34e60b6d0 | 271 | // and recieve when release |
jacksacane | 28:9413eb50156d | 272 | button.mode(PullUp); |
Nurchu | 31:39d04aedc3e5 | 273 | button.fall(&enterTransmitMode); |
Nurchu | 31:39d04aedc3e5 | 274 | button.rise(&enterRecieveMode); |
Nurchu | 27:08d34e60b6d0 | 275 | |
Nurchu | 27:08d34e60b6d0 | 276 | // Setup sampler to sample at a specific frequency |
Nurchu | 31:39d04aedc3e5 | 277 | sampler.attach(&sampleData, SAMPLE_PERIOD); |
Nurchu | 27:08d34e60b6d0 | 278 | |
Nurchu | 27:08d34e60b6d0 | 279 | // Heartbeat thread |
drechtmann3 | 1:fc0a2c17e086 | 280 | while (1) { |
Nurchu | 27:08d34e60b6d0 | 281 | myled4 = !myled4; |
jacksacane | 40:4f7d95c68d29 | 282 | setChannel(); // Poll the DIP switch and change channels accordingly |
Nurchu | 27:08d34e60b6d0 | 283 | Thread::wait(100); |
Nurchu | 12:efcfe4c0d9f2 | 284 | } |
Nurchu | 12:efcfe4c0d9f2 | 285 | } |