ECE 4180 - Final Project Team / Mbed 2 deprecated WalkieTalkie

Dependencies:   mbed 4DGL-uLCD-SE mbed-rtos nRF24L01P

Committer:
Nurchu
Date:
Wed Apr 18 15:09:32 2018 +0000
Revision:
7:0ac1f1ca8aa6
Parent:
2:dc046ff72566
Child:
10:a8fcfc869fa5
Filled out microphone skeleton functions / fixed up some compile errors

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nurchu 0:c35b54fb9c3c 1 #include "mbed.h"
Nurchu 7:0ac1f1ca8aa6 2 #include "rtos.h"
Nurchu 2:dc046ff72566 3 #include "Microphone.h"
drechtmann3 1:fc0a2c17e086 4 #include "nRF24L01P.h"
Nurchu 2:dc046ff72566 5
drechtmann3 1:fc0a2c17e086 6 Serial pc(USBTX, USBRX); // tx, rx
drechtmann3 1:fc0a2c17e086 7
drechtmann3 1:fc0a2c17e086 8 nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10); // mosi, miso, sck, csn, ce, irq
drechtmann3 1:fc0a2c17e086 9 DigitalOut myled1(LED1);
drechtmann3 1:fc0a2c17e086 10 DigitalOut myled2(LED2);
drechtmann3 1:fc0a2c17e086 11 DigitalOut myled3(LED3);
Nurchu 2:dc046ff72566 12
Nurchu 2:dc046ff72566 13 Microphone mymicrophone(p16);
Nurchu 0:c35b54fb9c3c 14
Nurchu 0:c35b54fb9c3c 15 int main() {
drechtmann3 1:fc0a2c17e086 16
drechtmann3 1:fc0a2c17e086 17 // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
drechtmann3 1:fc0a2c17e086 18 // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019)
drechtmann3 1:fc0a2c17e086 19 // only handles 4 byte transfers in the ATMega code.
drechtmann3 1:fc0a2c17e086 20 #define TRANSFER_SIZE 4
drechtmann3 1:fc0a2c17e086 21
drechtmann3 1:fc0a2c17e086 22 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
drechtmann3 1:fc0a2c17e086 23 int txDataCnt = 0;
drechtmann3 1:fc0a2c17e086 24 int rxDataCnt = 0;
drechtmann3 1:fc0a2c17e086 25
drechtmann3 1:fc0a2c17e086 26 my_nrf24l01p.powerUp();
drechtmann3 1:fc0a2c17e086 27
drechtmann3 1:fc0a2c17e086 28 // Display the (default) setup of the nRF24L01+ chip
drechtmann3 1:fc0a2c17e086 29 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() );
drechtmann3 1:fc0a2c17e086 30 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() );
drechtmann3 1:fc0a2c17e086 31 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
drechtmann3 1:fc0a2c17e086 32 pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
drechtmann3 1:fc0a2c17e086 33 pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
drechtmann3 1:fc0a2c17e086 34
drechtmann3 1:fc0a2c17e086 35 pc.printf( "Type keys to test transfers:\r\n (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE );
drechtmann3 1:fc0a2c17e086 36
drechtmann3 1:fc0a2c17e086 37 my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
drechtmann3 1:fc0a2c17e086 38
drechtmann3 1:fc0a2c17e086 39 my_nrf24l01p.setReceiveMode();
drechtmann3 1:fc0a2c17e086 40 my_nrf24l01p.enable();
drechtmann3 1:fc0a2c17e086 41
drechtmann3 1:fc0a2c17e086 42 void michello() {
drechtmann3 1:fc0a2c17e086 43 //read in, subtract 0.67 DC bias, take absolute value, and scale up .1Vpp to 15 for builtin LED display
drechtmann3 1:fc0a2c17e086 44 myleds = int(abs((mymicrophone - (0.67/3.3)))*500.0);
drechtmann3 1:fc0a2c17e086 45 //Use an 8kHz audio sample rate (phone quality audio);
drechtmann3 1:fc0a2c17e086 46 wait(1.0/8000.0);
drechtmann3 1:fc0a2c17e086 47 }
drechtmann3 1:fc0a2c17e086 48
drechtmann3 1:fc0a2c17e086 49 void sendmic() {
drechtmann3 1:fc0a2c17e086 50 whilte (1)
Nurchu 0:c35b54fb9c3c 51 }
drechtmann3 1:fc0a2c17e086 52
drechtmann3 1:fc0a2c17e086 53 void pchello() {
drechtmann3 1:fc0a2c17e086 54 // If we've received anything over the host serial link...
drechtmann3 1:fc0a2c17e086 55 if ( pc.readable() ) {
drechtmann3 1:fc0a2c17e086 56
drechtmann3 1:fc0a2c17e086 57 // ...add it to the transmit buffer
drechtmann3 1:fc0a2c17e086 58 txData[txDataCnt++] = pc.getc();
drechtmann3 1:fc0a2c17e086 59
drechtmann3 1:fc0a2c17e086 60 // If the transmit buffer is full
drechtmann3 1:fc0a2c17e086 61 if ( txDataCnt >= sizeof( txData ) ) {
drechtmann3 1:fc0a2c17e086 62
drechtmann3 1:fc0a2c17e086 63 // Send the transmitbuffer via the nRF24L01+
drechtmann3 1:fc0a2c17e086 64 my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
drechtmann3 1:fc0a2c17e086 65
drechtmann3 1:fc0a2c17e086 66 txDataCnt = 0;
drechtmann3 1:fc0a2c17e086 67 }
drechtmann3 1:fc0a2c17e086 68
drechtmann3 1:fc0a2c17e086 69 // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
drechtmann3 1:fc0a2c17e086 70 myled1 = !myled1;
drechtmann3 1:fc0a2c17e086 71 }
drechtmann3 1:fc0a2c17e086 72
drechtmann3 1:fc0a2c17e086 73 // If we've received anything in the nRF24L01+...
drechtmann3 1:fc0a2c17e086 74 if ( my_nrf24l01p.readable() ) {
drechtmann3 1:fc0a2c17e086 75
drechtmann3 1:fc0a2c17e086 76 // ...read the data into the receive buffer
drechtmann3 1:fc0a2c17e086 77 rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) );
drechtmann3 1:fc0a2c17e086 78
drechtmann3 1:fc0a2c17e086 79 // Display the receive buffer contents via the host serial link
drechtmann3 1:fc0a2c17e086 80 for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) {
drechtmann3 1:fc0a2c17e086 81
drechtmann3 1:fc0a2c17e086 82 pc.putc( rxData[i] );
drechtmann3 1:fc0a2c17e086 83 }
drechtmann3 1:fc0a2c17e086 84
drechtmann3 1:fc0a2c17e086 85 // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
drechtmann3 1:fc0a2c17e086 86 myled3 = !myled3;
drechtmann3 1:fc0a2c17e086 87 }
drechtmann3 1:fc0a2c17e086 88 }
drechtmann3 1:fc0a2c17e086 89 }
drechtmann3 1:fc0a2c17e086 90
drechtmann3 1:fc0a2c17e086 91 Mutex mux;
drechtmann3 1:fc0a2c17e086 92 Thread pcthread;
drechtmann3 1:fc0a2c17e086 93 Thread micthread;
drechtmann3 1:fc0a2c17e086 94 while (1) {
drechtmann3 1:fc0a2c17e086 95
drechtmann3 1:fc0a2c17e086 96
Nurchu 0:c35b54fb9c3c 97 }
drechtmann3 1:fc0a2c17e086 98 main (1) {
drechtmann3 1:fc0a2c17e086 99 while (1) {
drechtmann3 1:fc0a2c17e086 100
drechtmann3 1:fc0a2c17e086 101 }
drechtmann3 1:fc0a2c17e086 102 }