Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://buildbot.com.br/blog/comunicacao-wireless-com-o-modulo-nrf24l01/
- // Programa : Teste NRF24L01 - Emissor - Botoes
- // Autor : Adilson Thomsen
- #include <SPI.h>
- #include "nRF24L01.h"
- #include "RF24.h"
- int dados[1]; // Armazena os dados a enviar
- int pos[1];
- RF24 radio(9, 10); // Inicializa a placa nos pinos 9 (CE) e 10 (CS) do Arduino
- const uint64_t pipe = 0xE14BC8F482LL; // Define o endereco para comunicacao entre os modulos
- #define pino_botao1 7 // Define os pinos dos botoes
- #define pino_botao2 2
- #define pot A0
- int valorLido = 0;
- //-----------------------------------
- void setup()
- {
- pinMode(pino_botao1, INPUT_PULLUP); // Define os botoes como entrada e ativa pull-up
- pinMode(pino_botao2, INPUT_PULLUP);
- Serial.begin(57600); // Inicializa a serial
- Serial.println("Radio inicializado para transmitir ");
- Serial.println(" ");
- Serial.println("Pressione botao 1 ou 2 para iniciar a comunicacao...");
- radio.begin(); // Inicializa a comunicacao
- radio.openWritingPipe(pipe); // Entra em modo de transmissao
- }
- //-----------------------------------
- void loop()
- {
- valorLido = analogRead(pot);
- pos[0] = valorLido;
- Serial.println(pos[0]);
- if (digitalRead(pino_botao1) == LOW) // Envia o numero 1 caso o botao1 seja pressionado
- {
- delay(20);
- if (digitalRead(pino_botao1) == LOW) // Envia o numero 1 caso o botao1 seja pressionado
- {
- Serial.println("Botao 1 pressionado !");
- dados[0] = 1;
- radio.write(dados, 1);
- //delay(200);
- }
- }
- if (digitalRead(pino_botao2) == LOW) // Envia o numero 2 caso o botao2 seja pressionado
- {
- delay(20);
- if (digitalRead(pino_botao2) == LOW)
- {
- Serial.println("Botao 2 pressionado !");
- dados[0] = 2;
- radio.write(dados, 1);
- //delay(200);
- }
- }
- radio.write(pos, 1);
- }
- // http://shanes.net/another-nrf24l01-sketch-string-sendreceive/
- /*
- #include <SPI.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- #include <RF24_config.h>
- /*
- This sketch sends a string to a corresponding Arduino
- with nrf24 attached. It appends a specific value
- (2 in this case) to the end to signify the end of the
- message.
- */
- /*
- int msg[1];
- RF24 radio(9,10);
- const uint64_t pipe = 0xE8E8F0F0E1LL;
- //----------------------------------
- void setup(void)
- {
- Serial.begin(9600);
- radio.begin();
- radio.openWritingPipe(pipe);
- }
- //----------------------------------
- void loop(void)
- {
- String theMessage = "Hello there!";
- int messageSize = theMessage.length();
- for (int i = 0; i < messageSize; i++)
- {
- int charToSend[1];
- charToSend[0] = theMessage.charAt(i);
- radio.write(charToSend,1);
- }
- //send the 'terminate string' value...
- msg[0] = 2;
- radio.write(msg,1);
- /*delay sending for a short period of time. radio.powerDown()/radio.powerupp
- //with a delay in between have worked well for this purpose(just using delay seems to
- //interrupt the transmission start). However, this method could still be improved
- as I still get the first character 'cut-off' sometimes. I have a 'checksum' function
- on the receiver to verify the message was successfully sent.
- */
- /*
- radio.powerDown();
- delay(1000);
- radio.powerUp();
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement