receiver arduino codes
TRANSCRIPT
8/16/2019 Receiver Arduino Codes
http://slidepdf.com/reader/full/receiver-arduino-codes 1/3
/*####################Controller Program####################Created by: Bergonia, Joevann Tipdas, Darwin Umacob, Jay Adrian
Description This .ino file is created as a running program for thecontroller devices of the QuECE system.*/
//Libraries Used#include <LiquidCrystal.h>#include <nRF24L01.h>#include <RF24.h>#include <RF24_config.h>#include <SPI.h>
//Variables used//configuration for the nrf24 moduleRF24 radio(9,10);//configuration for the LCDLiquidCrystal lcd(7,6,5,4,3,2);
unsigned long msg[1];//designated pipes from the controllersconst uint64_t pipe1 = 0xE8E8F0F0E1LL, pipe2 = 0xE8E8F0F0E2LL, pipe3 = 0xE8E8F0F0E3LL, pipe4 = 0xE8E8F0F0E4L;const String ter = "_:";unsigned long pipe1Msg = 0,pipe2Msg = 0,pipe3Msg = 0,pipe4Msg = 0, empty = 0;//designated pipe numberuint8_t pipe_num;
//startup screenvoid setup(void){ Serial.begin(57600);
radio.begin(); lcd.begin(16,2); for(int i = 0; i <= 12; i++){ lcdSet(0,0,"Booting Up", true); for(int x = 0; x <= 3; x++){ lcd.print("."); delay(100); } }//sets PA level of nrf to its maximum option radio.setPALevel(RF24_PA_HIGH);//sets data rate of nrf to 2mbps(maximum data rate) radio.setDataRate(RF24_2MBPS);
//set the receiver to listen to the pipes for incoming count radio.openReadingPipe(1,pipe1); radio.openReadingPipe(2,pipe2); radio.openReadingPipe(3,pipe3); radio.openReadingPipe(4,pipe4); radio.startListening(); lcdSet(0,1,"Radio Listening", false);}
void loop(void){
8/16/2019 Receiver Arduino Codes
http://slidepdf.com/reader/full/receiver-arduino-codes 2/3
//checks if there is radio message available if (radio.available(&pipe_num)){ bool done = false; radio.read(msg, 1); unsigned long theData = msg[0]; if (msg[0] !=0){//checks from which pipe the data came from switch(pipe_num){ case 1: lcdSet(0,0, "Pipe 1 Received!", true); pipe1Msg = theData; break;
case 2: lcdSet(0,0, "Pipe 2 Received!", true); pipe2Msg = theData; break;
case 3: lcdSet(0,0, "Pipe 3 Received!", true); pipe3Msg = theData; break;
case 4:
lcdSet(0,0, "Pipe 4 Received!", true); pipe4Msg = theData; break; } }//send the message to serial for display else{ if(pipe1Msg != empty){ lcdSet(0,1, "Pipe 1 to Serial", false); Serial.print("a_"); Serial.print(pipe1Msg); Serial.println(ter); pipe1Msg = empty;
} if(pipe2Msg != empty){ lcdSet(0,1, "Pipe 2 to Serial", false); Serial.print("b_"); Serial.print(pipe2Msg); Serial.println(ter); pipe2Msg = empty; } if(pipe3Msg != empty){ lcdSet(0,1, "Pipe 3 to Serial", false); Serial.print("c_"); Serial.print(pipe3Msg); Serial.println(ter);
pipe3Msg = empty; } if(pipe4Msg != empty){ lcdSet(0,1, "Pipe 4 to Serial", false); Serial.print("d_"); Serial.print(pipe4Msg); Serial.println(ter); pipe4Msg = empty; } }