Created
June 13, 2016 00:12
-
-
Save TURBULENTE/0d82afa6e72b051cc1f39a85e068e966 to your computer and use it in GitHub Desktop.
Transmitter & receiver codes using the nrF24L01+ module, and MOMO board based on Arduino Leonardo & FabLeo's design. Arduino Compatible.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <nRF24L01.h> | |
#include <RF24.h> | |
RF24 radio(7, 8); | |
const byte rxAddr[6] = "00001"; | |
int poten; | |
void setup() | |
{ | |
while (!Serial); | |
Serial.begin(9600); | |
Serial.println("nrf24L01+ Receiver Starting!"); | |
radio.begin(); | |
radio.openReadingPipe(0, rxAddr); | |
radio.startListening(); | |
} | |
void loop() | |
{ | |
if (radio.available()) | |
{ | |
byte potenciometro[32]= {0}; | |
radio.read(&potenciometro, sizeof(potenciometro)); | |
Serial.print("pot= "); | |
Serial.println(potenciometro[0]); | |
} else { | |
Serial.println("no"); | |
} | |
delay(100); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ITS WORKING WITH THE MOMO BOARD & THE ARDUINO UNO FROM THE LAB. :D :D :D | |
#include <SPI.h> | |
#include <nRF24L01.h> | |
#include <RF24.h> | |
RF24 radio(7, 8); | |
const byte rxAddr[6] = "00001"; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.println("nrf24L01 + Transmitter Starting!"); | |
radio.begin(); | |
radio.setRetries(15, 15); | |
radio.openWritingPipe(rxAddr); | |
radio.stopListening(); | |
} | |
void loop() | |
{ | |
byte byteArray[] = {B00001111, B11110000, B00000000}; // creating an array filled with bits ( as much as you need ) | |
byte potenciometro = analogRead(A3); // getting potentiometer value as a byte | |
/*Const byte [32] = {0};*/ | |
byteArray[0] = byte(potenciometro); // filling array with potentiometer values as bytes | |
radio.write(&byteArray, sizeof(byteArray)); | |
Serial.println("valor del sensor"); | |
Serial.println(byte(potenciometro)); | |
for (int i = 0; i < 1; i++) { // for function to read byteArray, as I'm only using one potentiometer, I'm just reading 1 value | |
Serial.println("Valor del array de bytes"); | |
Serial.println(byteArray[i]); | |
} | |
delay(200); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment