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: MMA8451Q mbed nRF24L01P
Fork of Node_test_v2 by
main.cpp
00001 #include "mbed.h" 00002 #include "nRF24L01P.h" 00003 #include "MMA8451Q.h" 00004 #include <vector> 00005 #include <math.h> 00006 00007 #define MMA8451_I2C_ADDRESS (0x1d<<1) 00008 #define TRANSFER_SIZE 24 00009 00010 Serial pc(USBTX, USBRX); // tx, rx 00011 00012 PinName const SDA = PTE25; 00013 PinName const SCL = PTE24; 00014 00015 AnalogIn light_ain(A0); 00016 AnalogIn temp_ain(A1); 00017 AnalogIn pir_ain(A3); 00018 00019 nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTE1, PTE0, PTD0); // mosi, miso, sck, csn, ce, irq 00020 00021 DigitalOut myled1(LED1); 00022 DigitalOut myled2(LED2); 00023 00024 uint16_t light; 00025 uint16_t temp; 00026 uint16_t pir; 00027 00028 std::vector<uint16_t> light_data; 00029 std::vector<uint16_t> temp_data; 00030 std::vector<uint16_t> pir_data; 00031 00032 void getdata() 00033 { 00034 light = light_ain.read_u16(); 00035 temp = temp_ain.read_u16(); 00036 pir = pir_ain.read_u16(); 00037 00038 light_data.push_back (light); 00039 temp_data.push_back (temp); 00040 pir_data.push_back (pir); 00041 00042 light_data.pop_back(); 00043 temp_data.pop_back(); 00044 pir_data.pop_back(); 00045 00046 00047 printf("%f\n", light_data); 00048 00049 } 00050 00051 00052 int main() 00053 { 00054 00055 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); 00056 00057 light_data.assign (20,0); 00058 temp_data.assign (20,0); 00059 pir_data.assign (20,0); 00060 00061 00062 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; 00063 int txDataCnt = 0; 00064 int rxDataCnt = 0; 00065 00066 my_nrf24l01p.powerUp(); 00067 00068 // Display the (default) setup of the nRF24L01+ chip 00069 //pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); 00070 //pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); 00071 //pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); 00072 //pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); 00073 //pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); 00074 00075 //pc.printf( "Type keys to test transfers:\r\n (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE ); 00076 00077 my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); 00078 00079 my_nrf24l01p.setReceiveMode(); 00080 my_nrf24l01p.enable(); 00081 00082 printf("MMA8451 ID: %d\n", acc.getWhoAmI()); 00083 00084 while (1) { 00085 getdata(); 00086 00087 // txDataCnt = sprintf(txData, " %1.3f %1.3f %1.3f\n", x,y,z); 00088 //my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); 00089 myled1 = !myled1; 00090 wait(0.5); 00091 } 00092 00093 } 00094 00095
Generated on Wed Jul 13 2022 20:50:35 by
1.7.2
