project wireless
Dependencies: mbed nRF24L01P nRF24L01P_Hello_World TextLCD
Fork of nRF24L01P_Hello_World by
main.cpp
00001 #include "mbed.h" 00002 #include "nRF24L01P.h" 00003 #include "TextLCD.h" 00004 #include "SerialRPCInterface.h" 00005 SerialRPCInterface SerialInterface(USBTX, USBRX); 00006 Serial pc(USBTX, USBRX); // tx, rx 00007 TextLCD lcd(p15, p16, p21, p22, p23, p24); // rs, e, d4-d7 00008 nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10); // mosi, miso, sck, csn, ce, irq 00009 00010 DigitalOut myled1(LED1); 00011 DigitalOut myled2(LED2); 00012 DigitalOut ledlicht(p30); 00013 DigitalOut lednorm(p29); 00014 DigitalOut leddonk(p28); 00015 char a[5]; //temp 00016 char b[5];//licht 00017 char buffer[6];//buffer 00018 char aa = '?';//temp 00019 char bb = '?';//licht 00020 float temp = 0;//rpc 00021 float licht = 0;//rpc 00022 00023 RPCVariable<float> rpc_temp(&temp,"temp"); 00024 RPCVariable<float> rpc_licht(&licht,"licht"); 00025 00026 int main() 00027 { 00028 //Labview 00029 Base::add_rpc_class<AnalogIn>(); 00030 Base::add_rpc_class<AnalogOut>(); 00031 Base::add_rpc_class<DigitalIn>(); 00032 Base::add_rpc_class<DigitalOut>(); 00033 Base::add_rpc_class<DigitalInOut>(); 00034 Base::add_rpc_class<PwmOut>(); 00035 Base::add_rpc_class<Timer>(); 00036 Base::add_rpc_class<SPI>(); 00037 Base::add_rpc_class<BusOut>(); 00038 Base::add_rpc_class<BusIn>(); 00039 Base::add_rpc_class<BusInOut>(); 00040 Base::add_rpc_class<Serial>(); 00041 00042 char buf[256], outbuf[256]; 00043 00044 #define TRANSFER_SIZE 6 00045 00046 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; 00047 int txDataCnt = 0; 00048 int rxDataCnt = 0; 00049 00050 my_nrf24l01p.powerUp(); 00051 00052 //Set Device 00053 my_nrf24l01p.setTxAddress(0xE7E7E7E7E7,5); 00054 //my_nrf24l01p.setRxAddress(0xE7E7E7E7E7,5); 00055 my_nrf24l01p.setRfFrequency(2450); 00056 my_nrf24l01p.setRfOutputPower(0); 00057 00058 // Display the (default) setup of the nRF24L01+ chip 00059 // pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); 00060 // pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); 00061 // pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); 00062 // pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); 00063 // pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress(0) ); 00064 00065 //pc.printf( "Type keys to test transfers:\r\n (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE ); 00066 00067 my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); 00068 00069 my_nrf24l01p.setReceiveMode(); 00070 my_nrf24l01p.enable(); 00071 00072 00073 00074 lcd.cls();//LCD clear 00075 lcd.locate(0,0); 00076 lcd.printf("Project wireless"); 00077 lcd.locate(0,1); 00078 lcd.printf("Bjorn Vranken"); 00079 lcd.locate(0,1); 00080 wait(1); 00081 lcd.printf("Michiel VEndert"); 00082 lcd.locate(0,1); 00083 wait(1); 00084 lcd.printf("Nino DerKinderen"); 00085 wait(2); 00086 00087 lcd.cls();//LCD clear 00088 lcd.locate(0,0); 00089 lcd.printf("Temp:"); 00090 lcd.locate(0,1); 00091 lcd.printf("Licht:"); 00092 lcd.locate(12,0); 00093 lcd.printf("C"); 00094 lcd.locate(12,1); 00095 lcd.putc(37); 00096 00097 temp = 10; 00098 licht = 50; 00099 00100 while (1) 00101 { 00102 pc.gets(buf,256); 00103 rpc(buf,outbuf); 00104 pc.printf("%s\n",outbuf); 00105 00106 for(int i = 0;i <= 20; i++) 00107 { 00108 wait(0.05); 00109 // If we've received anything in the nRF24L01+... 00110 if ( my_nrf24l01p.readable(NRF24L01P_PIPE_P0) ) { 00111 // ...read the data into the receive buffer 00112 rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) ); 00113 00114 // Display the receive buffer contents via the host serial link 00115 for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) 00116 { 00117 buffer[i] = rxData[i]; 00118 //pc.putc( rxData[i] ); 00119 } 00120 00121 // Toggle LED1 (to help debug nRF24L01+ -> Host communication) 00122 myled1 = !myled1; 00123 //pc.printf("\r\n"); 00124 00125 if (buffer[5] == 'T') 00126 { 00127 //pc.printf("Temperatuur\r\n"); 00128 for(int x = 0; x <=4; x++) 00129 { 00130 a[x] = buffer[x]; 00131 aa = a[x]; 00132 lcd.locate(6+x,0); 00133 lcd.putc(aa); 00134 } 00135 temp = atof(a); 00136 //pc.printf("t : %f \r\n",temp); 00137 } 00138 else if (buffer[5] == 'L') 00139 { 00140 //pc.printf("Lichtwaarde\r\n"); 00141 for(int x = 0; x <=4; x++) 00142 { 00143 b[x] = buffer[x]; 00144 bb = b[x]; 00145 lcd.locate(6+x,1); 00146 lcd.putc(bb); 00147 } 00148 licht = atof(b); 00149 //pc.printf("l : %f \r\n",licht); 00150 if(licht > 85) 00151 { 00152 ledlicht = 1; 00153 lednorm = 0; 00154 leddonk = 0; 00155 } 00156 else if(licht <= 85 && licht > 30) 00157 { 00158 ledlicht = 0; 00159 lednorm = 1; 00160 leddonk = 0; 00161 } 00162 else if(licht <= 30) 00163 { 00164 ledlicht = 0; 00165 lednorm = 0; 00166 leddonk = 1; 00167 } 00168 } 00169 else 00170 { 00171 //pc.printf("Verkeerde DATA!!!\r\n"); 00172 } 00173 } 00174 } 00175 } 00176 }
Generated on Tue Jul 12 2022 19:17:04 by 1.7.2