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
Diff: main.cpp
- Revision:
- 25:02cdaf98e4ab
- Parent:
- 24:28c8b01b7d35
- Parent:
- 22:e835b3490280
- Child:
- 26:57731422b129
--- a/main.cpp Sat Apr 21 17:51:24 2018 +0000 +++ b/main.cpp Sat Apr 21 17:55:10 2018 +0000 @@ -5,6 +5,7 @@ #include "Speaker.h" #include "HUD.h" #include "nRF24L01P.h" +#include "uLCD_4DGL.h" #include "CircularBuf.h" #include "CircularBuf.cpp" // Hack to get templates to work @@ -21,10 +22,13 @@ Microphone mymicrophone(p16); nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10); // mosi, miso, sck, csn, ce, irq +uLCD_4DGL uLCD(p27,p28,p30); // serial tx, serial rx, reset pin; CircularBuf<uint8_t> txbuff(30); CircularBuf<uint8_t> rxbuff(30); Ticker t; //10:41 am 4/20 + InterruptIn Button(p18); //changed DitialIn to InterruptIn at 5:54 4/18/18 +Thread lcd; char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; //making these usable by other voids. int txDataCnt = 0;//and this. @@ -32,6 +36,18 @@ uint8_t micvalue[30]; int micvalcount = 0; +int rfFreq; +int dataRate; +unsigned long long rxAddr, txAddr; + +enum operatingMode { + RECEIVE = 0, + TRANSMIT +}; + +operatingMode mode; + + void startup() { @@ -104,6 +120,7 @@ uint8_t spkrarray[30]; uint8_t spkrtemp; while (Button.read() == 0) { + mode = RECEIVE; if (my_nrf24l01p.readable(0)) { pc.printf("receiving...."); my_nrf24l01p.read(0, (char*)spkrarray, 30); @@ -123,6 +140,7 @@ // } // txData[txDataCnt++] = ; spkr.turnOff(); + uint8_t txsendary[30]; txbuff.pop(txsendary, 30); while (Button.read()) { @@ -130,6 +148,7 @@ pc.printf("transmitting...."); my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char*) txsendary, 30); myled1 = !myled1; + mode = TRANSMIT; } } @@ -146,6 +165,30 @@ } +void lcdThread() +{ + while (1) { + uLCD.locate(64, 20); + uLCD.printf("Frequency: %d MHz", rfFreq); + uLCD.locate(64, 40); + uLCD.printf("Data Rate: %d kbps", dataRate); + uLCD.locate(64, 60); + uLCD.printf("TX Address: 0x%010llX", txAddr); + uLCD.locate(64, 80); + uLCD.printf("RX Address: 0x%010llX", rxAddr); + uLCD.locate(64, 100); + switch (mode) { + case RECEIVE: + uLCD.printf("Mode: Receiving"); + break; + case TRANSMIT: + uLCD.printf("Mode: Transmitting"); + break; + } + // Maybe add some graphics too idk + } +} + int main() { startup(); @@ -154,7 +197,32 @@ Button.rise(&transmit); Button.fall(&receive); t.attach(&pollmic, 0.1); - // t.attach(&receive, 0.0001); + + rfFreq = my_nrf24l01p.getRfFrequency(); + dataRate = my_nrf24l01p.getAirDataRate(); + rxAddr = my_nrf24l01p.getRxAddress(); + txAddr = my_nrf24l01p.getTxAddress(); + + my_nrf24l01p.setTransferSize(TRANSFER_SIZE); + + my_nrf24l01p.setReceiveMode(); + my_nrf24l01p.enable(); + + mode = RECEIVE; + + // Initialize the uLCD + uLCD.baudrate(3000000); + uLCD.background_color(BLACK); + + // Register interrupts + Button.mode(PullUp);//added 6:23pm 4/18/18 + t.attach(&pollmic, 0.0001); + t.attach(&receive, 0.0001); + + // Spawn threads + lcd.start(lcdThread); + + // Main thread while (1) { Thread::yield(); }