code pour piloter les balises

Dependencies:   mbed RF24

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include <RF24.h>
00003  
00004 
00005 RF24 device(SPI_MOSI, SPI_MISO, SPI_SCK, D9, SPI_CS);
00006 DigitalIn ms(D2);
00007 DigitalIn mybutton(USER_BUTTON);
00008 const uint64_t pipe_address = 0xF0F0F0F0AA;
00009 
00010 void receiver();
00011 void transmitter(char* message);
00012  
00013 int main() {
00014     
00015     device.begin();
00016     
00017     char message[32] = "vv";
00018     
00019      if (ms){
00020                 device.openWritingPipe(pipe_address);
00021                 
00022             } else{
00023             /*slave*/
00024                 
00025         device.openReadingPipe(1,pipe_address);
00026         device.startListening();                           
00027             
00028             }
00029     
00030     
00031     while (1){
00032         
00033         
00034         if (ms){
00035             /*master*/
00036             if (mybutton == 0) {
00037                 
00038                 transmitter(message);
00039                 printf("%s => emis : %d\r\n",message,sizeof(message));
00040                 wait(0.2);
00041                 
00042         }
00043                 
00044             } else{
00045             /*slave*/
00046                 
00047                 receiver();                               
00048             }
00049     }
00050 
00051 }
00052 
00053 void transmitter(char* message){
00054         device.write(message,sizeof(message));
00055     }
00056     
00057 void receiver(){
00058         
00059 
00060        // if (device.available()){  
00061                   
00062             char text[32];
00063             device.read(&text, sizeof(text));
00064             if (text[0]!='\0')
00065                 printf("%s recu : %d\n\r",text,sizeof(text));
00066       //  }
00067     }
00068 
00069