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